shell - Jenkins Pipeline 插件看似跳过命令

标签 shell jenkins groovy continuous-integration jenkins-pipeline

我有一个 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"
    }
}

关于shell - Jenkins Pipeline 插件看似跳过命令,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40804522/

相关文章:

linux - Linux find 命令如何与 exec 一起使用

linux - 你能用Linux shell加载内存中的树结构吗?

regex - 正则表达式 : bash 3 vs bash 4

Linux 脚本错误-意外 token fi 附近的语法错误

grails - 模拟groovy.sql.Sql.call(_,_,_)方法

javascript - 尝试用 JavaScript 创建非常简单的闭包

maven - 在 Jenkins 中将 WAR 文件部署到 Tomcat

jenkins - 在 Jenkins 上重新运行失败测试的插件

jenkins - 使用 Spock 的 Groovy 共享库测试流水线步骤方法

grails - 建立搜寻标准并不容易?