Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
471 views
in Technique[技术] by (71.8m points)

groovy - How to I get the url of build triggered with build step on Jenkins?

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.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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 @NonCPS

If 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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...