是否可以从构建步骤检索响应?

时间:2019-01-15 12:03:49

标签: jenkins jenkins-pipeline

让我们假设作业A呼叫作业B的场景:

...
...
...

crID = build (job: "Open Change Request", wait: true, parameters: [
  string(name: "assignedTo", value: "${BUILD_USER_EMAIL}"),
  string(name: "crType", value: "Upgrade worker nodes"),
  string(name: "environment", value: "${region}")]).result

上面的代码有缺陷,因为result将返回FAILURESUCCESS等...
我需要的是实际检索作业B产生的值。

这是否有可能检索在build步骤中运行的作业的响应?

可能性:

  • 从其他作业中读取日志吗?
  • 全局属性?

1 个答案:

答案 0 :(得分:0)

最后,我通过阅读构建日志来做到这一点。

在作业B中打印要记录的值:

echo "Change Request ID:${crID}"

在作业A中处理日志文本以获取打印值:

openCrRawData = build (job: "Open Change Request", wait: true, parameters: [
   string(name: "assignedTo", value: "${jobInitiator}"),
   string(name: "crType", value: "Upgrade worker nodes"),
   string(name: "environmentsForCR", value: "${region}")])

crIDRaw = sh (script: "echo \"${openCrRawData.rawBuild.log}\" | grep \"Change Request ID:\"", returnStdout: true).trim().split(":")
crID = crIDRaw[1]