Jenkins Pipeline 插件看似跳过命令

Jenkins Pipeline plugin seemingly skipping commands

我有一个 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 命令。所有其他的都被忽略。似乎没有发生错误。

如何让所有命令都执行?

您的脚本 运行 成功并在

后按预期运行
  1. node{ }
  2. 包围它
  3. 使用 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"
    }
}