【问题标题】:Jenkins shell hiding stacktrace loses curl outputJenkins shell 隐藏堆栈跟踪丢失 curl 输出
【发布时间】:2019-01-23 15:25:54
【问题描述】:

我正在尝试从以下脚本中隐藏堆栈跟踪:

def status = "false"
  while (status.equals("false")) {
      sleep 5
      status = sh(
            script: "curl -s -H 'Accept: application/json' http://my.ip | jq \'.completed\' ",
            returnStdout: true
      ).trim()
    echo "status: ${status}"
  }

输出:

+ curl -s -H 'Accept: application/json' 'http://my.ip'
+ jq .completed
status: true

如果我只想看到输出消息,我必须在脚本正文中写“set +x”。但这会导致状态返回为 NULL。

status = sh(
      script:'''
      set +x
      script: "curl -s -H 'Accept: application/json' http://my.ip | jq \'.completed\'
      ''',
      returnStdout: true
).trim()

输出:

status: NULL

为什么输出会丢失,有没有其他方法可以删除堆栈跟踪?

【问题讨论】:

    标签: bash jenkins sh jenkins-pipeline stack-trace


    【解决方案1】:

    这里的修复是我声明多行脚本错误。对于这种情况,它应该使用双引号而不是单引号。所以解决方案:

    script: """
      my 
      script
      here
    """,
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-06-29
      • 2018-01-30
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多