Android CI使用Bitbucket管道和Docker

问题描述 投票:24回答:3

我正在尝试在Bitbucket Pipelines for Android中设置持续集成(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,而是Pipelines将Bitbucket仓库的内容复制到容器的工作目录:

/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
android docker continuous-integration bitbucket bitbucket-pipelines
3个回答
11
投票

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


0
投票

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

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

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


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
© www.soinside.com 2019 - 2024. All rights reserved.