问题描述
我想在Jenkins中使用Docker container 来编译代码。
就是每次github上面push commit的时候就触发Jenkins来自动化编译。
问题出现的平台版本及自己尝试过哪些方法
我目前使用的是pipeline,但是从log看来好像没有使用Docker来编译代码。
相关代码
// 请把代码文本粘贴到下方(请勿用图片代替代码)
Jenkinsfile
pipeline {
agent none
stages {
stage('Build') {
agent {
docker { image 'zequanhannto/tina' }
}
steps {
sh "echo $PWD"
sh "source build/envsetup.sh"
sh "lunch astar_parrot-tina"
sh "make -j"
sh "pack -d"
}
}
stage('Test') {
steps {
echo 'Testing..'
}
}
stage('Deploy') {
steps {
echo 'Deploying....'
}
}
}
}
Jenkins build log:
Started by user admin
Running in Durability level: MAX_SURVIVABILITY
[Pipeline] stage
[Pipeline] { (Build)
[Pipeline] node
Running on Jenkins in /root/.jenkins/workspace/tina-pipeline
[Pipeline] {
[Pipeline] sh
[tina-pipeline] Running shell script
+ docker inspect -f . zequanhannto/tina
.
[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 ******** -e ******** zequanhannto/tina cat
$ docker top f2049aa68d08f2c3fd548d2cabe8b6aae779db26a98f72b2e83146b51206405c -eo pid,comm
[Pipeline] {
[Pipeline] sh
[tina-pipeline] Running shell script
+ echo /root/jenkins
/root/jenkins
[Pipeline] sh
[tina-pipeline] Running shell script
+ source build/envsetup.sh
/root/.jenkins/workspace/tina-pipeline@tmp/durable-5556332e/script.sh: 2: /root/.jenkins/workspace/tina-pipeline@tmp/durable-5556332e/script.sh: source: not found
[Pipeline] }
$ docker stop --time=1 f2049aa68d08f2c3fd548d2cabe8b6aae779db26a98f72b2e83146b51206405c
$ docker rm -f f2049aa68d08f2c3fd548d2cabe8b6aae779db26a98f72b2e83146b51206405c
[Pipeline] // withDockerContainer
[Pipeline] }
[Pipeline] // node
[Pipeline] }
[Pipeline] // stage
[Pipeline] stage
[Pipeline] { (Test)
Stage "Test" skipped due to earlier failure(s)
[Pipeline] }
[Pipeline] // stage
[Pipeline] stage
[Pipeline] { (Deploy)
Stage "Deploy" skipped due to earlier failure(s)
[Pipeline] }
[Pipeline] // stage
[Pipeline] End of Pipeline
ERROR: script returned exit code 127
Finished: FAILURE
你期待的结果是什么?实际看到的错误信息又是什么?
我加了个echo $PWD结果出现的是我host上面的文件夹,当我使用agent在Jenkinsfile里面的时候难道不是全部steps都在新建的docker container里面运行吗?该如何解决?