Android CI使用Bitbucket管道和Docker

时间:2016-06-01 00:12:13

标签: android docker continuous-integration bitbucket bitbucket-pipelines

我正在尝试在Android Bitbucket Pipelines中设置持续集成(CI)。

我使用Android Studio 2.1.1创建了一个示例空白活动。

使用Pipelines我正在使用uber/android-build-environment Docker容器,它可以很好地创建环境。这是我的bitbucket-pipelines.yml

image: uber/android-build-environment:latest

pipelines:
  default:
    - step:
        script:
          - echo y | android update sdk --filter "extra-android-m2repository" --no-ui -a # Grab the Android Support Repo which isn't included in the container
          - ./gradlew assembleDebug

需要进行一些更改,因为uber/android-build-environment期望像这样运行:

docker run -i -v $PWD:/project -t uber/android-build-environment /bin/bash /project/ci/build.sh

例如,源不会复制到卷/project,而是将Pipebucket repo的内容复制到容器的工作目录:

/opt/atlassian/bitbucketci/agent/build

./gradlew assembleDebug运行时,我收到以下错误:

...

FAILURE: Build failed with an exception.

* What went wrong:
Could not create service of type TaskArtifactStateCacheAccess using TaskExecutionServices.createCacheAccess().
> Failed to create parent directory '/opt/atlassian/bitbucketci/agent/build/.gradle' when creating directory '/opt/atlassian/bitbucketci/agent/build/.gradle/2.10/taskArtifacts'

* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.

BUILD FAILED

Total time: 56.449 secs

在工作目录中运行ls -al会产生:

ls -al
total 52
drwxr-xr-x 5 root root 4096 May 31 22:33 .
drwxr-xr-x 3 root root 4096 May 31 22:43 ..
drwxr-xr-x 3 root root 4096 May 31 22:33 app
-rw-r--r-- 1 root root  462 May 31 22:33 bitbucket-pipelines.yml
-rw-r--r-- 1 root root  498 May 31 22:33 build.gradle
drwxr-xr-x 8 root root 4096 May 31 22:33 .git
-rw-r--r-- 1 root root  387 May 31 22:33 .gitignore
drwxr-xr-x 3 root root 4096 May 31 22:33 gradle
-rw-r--r-- 1 root root  855 May 31 22:33 gradle.properties
-rwxr-xr-x 1 root root 4971 May 31 22:33 gradlew
-rw-r--r-- 1 root root 2314 May 31 22:33 gradlew.bat
-rw-r--r-- 1 root root   15 May 31 22:33 settings.gradle

3 个答案:

答案 0 :(得分:11)

这是他们系统中的一个错误,我向他们报告了它(issue url,它已经很长了)并且已经修复了它(fix url)。我已经测试了我的项目,它成功建立。尝试现在建立你的项目,祝你好运。

答案 1 :(得分:0)

您可以从容器中将项目从/opt/atlassian/bitbucketci/agent/build符号链接到/project吗? ln -s /opt/atlassian/bitbucketci/agent/build /project是您需要的命令。

或者将文件复制到新路径?

我没有使用android开发的经验,所以YMMV:)

答案 2 :(得分:0)

似乎不再支持uber/android-build-environment

我最终使用javiersantos/android-ci代替,它完全可以从头开始。

只需将以下内容添加到 bitbucket-pipeline.yml:

image: javiersantos/android-ci:27.0.3

pipelines:
  default:
    - step:
        script:
          - export GRADLE_USER_HOME=`pwd`/.gradle
          - chmod +x ./gradlew
          - ./gradlew assembleDebug