我想在每次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容器中吗?