While using Groovy based pipelines in Jenkins you can trigger child jobs using the the build stage.
Still the documentation above states nothing regarding what kind of return object you would get and what attributes it has.
The only thing I found so far is that I can use build.getResult()
to obtain the result of the triggered job.
Still, I do want to obtain the URL of this job.
From the documentation for the build
step in /pipeline-syntax
(waitFormCompletion
argument, the original has better formatting):
You may ask that this Pipeline build wait for completion of the downstream build. In that case the return value of the step is an object on which you can obtain the following read-only properties: so you can inspect its .result and so on.
- number
build number (integer)- result
typically SUCCESS, UNSTABLE, or FAILURE (may be null for an ongoing build)- currentResult
typically SUCCESS, UNSTABLE, or FAILURE. Will never be null.- resultIsBetterOrEqualTo(String)
Compares the current build result to the provided result string (SUCCESS, UNSTABLE, or FAILURE) and returns true if the current build result is better than or equal to the provided result.- resultIsWorseOrEqualTo(String)
Compares the current build result to the provided result string (SUCCESS, UNSTABLE, or FAILURE) and returns true if the current build result is worse than or equal to the provided result.- displayName
normally #123 but sometimes set to, e.g., an SCM commit identifier- description
additional information about the build- id
normally number as a string- timeInMillis
time since the epoch when the build was scheduled- startTimeInMillis
time since the epoch when the build started running- duration
duration of the build in milliseconds- durationString
a human-readable representation of the build duration- previousBuild
another similar object, or null- nextBuild
similarly- absoluteUrl
URL of build index page- buildVariables
for a non-Pipeline downstream build, offers access to a map of defined build variables; for a Pipeline downstream build, any variables set globally on env- changeSets
a list of changesets coming from distinct SCM checkouts; each has a kind and is a list of commits; each commit has a commitId, timestamp, msg, author, and affectedFiles each of which has an editType and path; the value will not generally be Serializable so you may only access it inside a method marked @NonCPS- rawBuild
a hudson.model.Run with further APIs, only for trusted libraries or administrator-approved scripts outside the sandbox; the value will not be Serializable so you may only access it inside a method marked @NonCPSIf you do not wait, this step succeeds so long as the downstream build can be added to the queue (it will not even have been started). In that case there is currently no return value.
The job URL doesn't exist (it's a build, after all), but absoluteUrl
gives you the build URL.
rawBuild
should let you access e.g. rawbuild.parent.url
(untested), but it's generally unsafe and discouraged to leave the sandbox.
The previous answer is fine only for passed Jobs. Failing ones return null from build step. There is a corresponding Bug https://issues.jenkins-ci.org/browse/JENKINS-48475. It's set as RESOLVED because such behavior is expected, but IMO that's not correct as there is not alternative to get info from failed jobs
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With