Idan Adar
Idan Adar

Reputation: 44516

Is it possible to retrieve response from build step?

Lets assume a scenario where Job A calls Job 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

The above code is flawed, as result will return FAILURE, SUCCESS, etc...
What I require is to actually retrieve the value that Job B generates.

Is this at all possible, to retrieve the response of the job that ran as part of a build step?

Possibilities:

Upvotes: 1

Views: 174

Answers (1)

Idan Adar
Idan Adar

Reputation: 44516

I ended up doing so by reading the build log.

In job B print the value to log:

echo "Change Request ID:${crID}"

In job A process the log text to get the printed value:

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]

Upvotes: 1

Related Questions