我有一个 Jenkins Pipeline plugin脚本看起来像这样:
stage("check out project") {
shell "pwd"
echo "test 1"
git credentialsId: "user", url: "http://url/project"
echo "test 2"
shell "git --version"
echo "test 3"
}
构建的输出是这样的:
[Pipeline] stage
[Pipeline] { (check out project)
[Pipeline] echo
test 1
[Pipeline] echo
test 2
[Pipeline] echo
test 3
[Pipeline] }
[Pipeline] // stage
[Pipeline] End of Pipeline
Finished: SUCCESS
从输出和构建时间来看,只执行了 echo 命令。所有其他的都被忽略。似乎没有发生错误。
如何让所有命令都被执行?
最佳答案
您的脚本成功运行并按预期工作
- 用
node{ }
和 包围它
- 使用
sh
代替shell
像这样:
node{
stage("check out project") {
sh "pwd"
echo "test 1"
git credentialsId: '12341234-1234-1234-1234-123412341234', url: "git@github.com:sendgrid/sendgrid-java.git"
echo "test 2"
sh "git --version"
echo "test 3"
}
}
关于shell - Jenkins Pipeline 插件看似跳过命令,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40804522/