让我们假设作业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
将返回FAILURE
,SUCCESS
等...
我需要的是实际检索作业B产生的值。
这是否有可能检索在build
步骤中运行的作业的响应?
可能性:
答案 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]