我已在我的本地计算机上安装了Jenkins,该计算机在MacOS High Sierra上运行并安装了docker。我正在尝试运行一个使用docker的简单管道示例。我已将以下行添加到管道中:
pipeline {
agent {
docker 'node'
}
stages {
stage("testing 123") {
steps {
sh 'node --version'
}
}
}
}
然后从WebGUI,我现在点击构建,它失败了。控制台输出显示错误docker: command not found
。完整的错误日志如下:
Started by user Happycoder
Running in Durability level: MAX_SURVIVABILITY
[Pipeline] node
Running on Jenkins in /Users/Shared/Jenkins/Home/workspace/test
[Pipeline] {
[Pipeline] sh
[test] Running shell script
+ docker inspect -f . node
/Users/Shared/Jenkins/Home/workspace/test@tmp/durable-20ded4c0/script.sh: line 2: docker: command not found
[Pipeline] sh
[test] Running shell script
+ docker pull node
/Users/Shared/Jenkins/Home/workspace/test@tmp/durable-ebdc1549/script.sh: line 2: docker: command not found
[Pipeline] }
[Pipeline] // node
[Pipeline] End of Pipeline
ERROR: script returned exit code 127
Finished: FAILURE
为什么会这样?在Jenkins文档中,它们仅提供此语法,并未提及任何其他内容。
答案 0 :(得分:1)
我认为以下部分不正确:
agent {
docker 'node'
}
此命令将尝试启动与'节点关联的Docker容器。标签
如果要测试声明性管道,则应尝试使用此语法(如果要构建Maven项目):
agent {
docker {
image 'maven:3.5.0-jdk-8'
}
}
仅供参考,你可以找到很多管道示例here。