简体   繁体   English

如何在 Jenkins 上的 docker 图像中运行快车道

[英]How to run a fastlane lane in a docker image on Jenkins

I'm using Jenkins to run the CI.我正在使用 Jenkins 来运行 CI。 I'm using the docker image mingc/android-build-box to run a fastlane lane ( dokka ) in a container.我正在使用 docker 映像mingc/android-build-box在容器中运行快车道 ( dokka )。 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.操作成功,但所有生成的文件都归 root 所有。 This breaks the CI because I can't delete them when they are not necessary anynmore.这会破坏 CI,因为不再需要它们时我无法删除它们。

I tried to pass the CI user:我试图通过 CI 用户:

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 将临时使用 `/tmp/bundler20200511-6-m21qkb6' 作为您的主目录。 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 bundler:加载失败命令:fastlane (/usr/local/bin/fastlane) Bundler::GemNotFound:在任何源中都找不到 aws-eventstream-1.1.0

So I tried to call bundle install --deployment before bundle exec and now I get the error:所以我尝试在bundle install --deployment之前调用 bundle bundle exec ,现在我得到了错误:

fileutils.rb:232:in `mkdir': [.] Permission denied @ dir_s_mkdir - /:fastlane (Errno::EACCES) 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.我用谷歌搜索了这个错误,我发现了很多报告,但没有一个包含有用的答案,无论如何,这并不理想,因为 docker 图像已经安装了 fastlane gem,能够在没有的情况下使用它会很好不得不重新安装它。

Another solution would be to let the container run with root as user and then delete the files after having used them.另一种解决方案是让容器以 root 用户身份运行,然后在使用文件后删除文件。 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.如果您在 Jenkins 中运行它,它的标准 Docker 支持会为您处理安装、权限 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. Jenkins 会将WORKDIR挂载到容器中(在相同的路径上),以相同的用户 ID 运行,保持相同的工作目录,等等。 You can see in its logs the (rather long) docker run command it uses.您可以在其日志中看到它使用的(相当长的) docker run命令。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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