简体   繁体   中英

How to run a fastlane lane in a docker image on Jenkins

I'm using Jenkins to run the CI. I'm using the docker image mingc/android-build-box to run a fastlane lane ( dokka ) in a container. If I follow the guidelines suggested here and I run:

docker run --rm -v `pwd`:/project mingc/android-build-box bash -c 'cd /project; bundle exec fastlane dokka'

the operation succeeds but all the generated files are owned by root. This breaks the CI because I can't delete them when they are not necessary anynmore.

I tried to pass the CI user:

docker run --rm --user $(id -u):$(id -g) -v `pwd`:/project mingc/android-build-box bash -c "cd /project; bundle install --deployment; bundle exec fastlane dokka"

I get the error:

/ is not writable. Bundler will use `/tmp/bundler20200511-6-m21qkb6' as your home directory temporarily. bundler: failed to load command: fastlane (/usr/local/bin/fastlane) Bundler::GemNotFound: Could not find aws-eventstream-1.1.0 in any of the sources

So I tried to call bundle install --deployment before bundle exec and now I get the error:

fileutils.rb:232:in `mkdir': [.] Permission denied @ dir_s_mkdir - /:fastlane (Errno::EACCES)

I googled the error and I've found many reports but none of them contains a useful answer and anyway, this wouldn't be ideal because the docker image already has the fastlane gem installed and it would be good to be able to use it without having to reinstall it.

Another solution would be to let the container run with root as user and then delete the files after having used them. This solution is not ideal either because I would have to remember to delete every file created but the container.

If you're running this in Jenkins, its standard Docker support handles the mounts, permissions, etc. for you. In scripted pipeline code, it should be enough to do

docker.inside('mingc/android-build-box') {
  sh 'bundle exec fastlane dokka'
}

Jenkins will mount the WORKDIR into the container (on an identical path), run as the same user ID, keep the same working directory, and so on. You can see in its logs the (rather long) docker run command it uses.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM