docker - 如何使用 Jenkins 在 docker 容器中构建 github 项目?
问题描述
我想在 Jenkins 每次收到来自 github 的提交推送时触发 github 项目的构建,然后使用我指定的 docker 映像在 docker 容器内构建项目。
目前,我有如下 Jenkinsfile:
pipeline {
agent {
docker { image 'docker-image' }
}
stages {
stage('Build') {
steps {
sh "source build/envsetup.sh"
sh "lunch astar_parrot-tina"
sh "make -j"
sh "pack -d"
}
}
}
}
并出现以下错误:
Started by user admin
Running in Durability level: MAX_SURVIVABILITY
[Pipeline] node
Running on Jenkins in /root/.jenkins/workspace/tina-pipeline
[Pipeline] {
[Pipeline] sh
[tina-pipeline] Running shell script
+ docker inspect -f . docker-image
.
[Pipeline] withDockerContainer
Jenkins does not seem to be running inside a container
$ docker run -t -d -u 0:0 -w /root/.jenkins/workspace/tina-pipeline -v /root/.jenkins/workspace/tina-pipeline:/root/.jenkins/workspace/tina-pipeline:rw,z -v /root/.jenkins/workspace/tina-pipeline@tmp:/root/.jenkins/workspace/tina-pipeline@tmp:rw,z -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** zequanhannto/tina cat
$ docker top 459169f2aea2499f4c361291733308fafa74ec63e08b7a1b74814e0bb9077d51 -eo pid,comm
[Pipeline] {
[Pipeline] stage
[Pipeline] { (Build)
[Pipeline] sh
[tina-pipeline] Running shell script
+ source build/envsetup.sh
/root/.jenkins/workspace/tina-pipeline@tmp/durable-386f0363/script.sh: 2: /root/.jenkins/workspace/tina-pipeline@tmp/durable-386f0363/script.sh: source: not found
[Pipeline] }
[Pipeline] // stage
[Pipeline] }
$ docker stop --time=1 459169f2aea2499f4c361291733308fafa74ec63e08b7a1b74814e0bb9077d51
$ docker rm -f 459169f2aea2499f4c361291733308fafa74ec63e08b7a1b74814e0bb9077d51
[Pipeline] // withDockerContainer
[Pipeline] }
[Pipeline] // node
[Pipeline] End of Pipeline
ERROR: script returned exit code 127
Finished: FAILURE
我不明白为什么 Jenkins 不运行 docker 容器内的步骤。我在想所有的步骤都将在 docker 容器内执行。如何让 Jenkins 运行 docker 容器内的所有步骤?并且在执行这些步骤之前会不会将github项目的所有代码复制到docker容器中?
解决方案
推荐阅读
- c# - 从每个访问先前返回的值?
- c++ - 并行块中的非并行 for 循环
- c# - 由于跨域框架,我自己的内容没有加载到 iframe 中
- javascript - 编写具有 Web 程序集依赖的 Typescript 库?
- java - Hibernate ORM 是否兼容 GraalVM 原生镜像编译?
- javascript - 在 TypeScript 中强制执行对象键
- powershell - 通过 Powershell Scripting 报告 Jira 工作日志
- java - Mapstruct:将对象内部的列表映射到对象列表
- sql-server - 如何检查 SQL Server 登录是否具有角色“SysAdmin”
- jquery - 选择更改时删除部分 URL 的下拉菜单 | Shopify