15
votes

How do you access current, and related, build information from within a Jenkins workflow groovy script?

I can see things like currentBuild.result and currentBuild.previousBuild being documented, but I can't see how I can access, for example:

  • The URL of the current build job.
  • The URL of build jobs that this workflow triggered.
  • The console output of a particular failed build job, etc.

Thanks for any pointers.

1
Where did you find documentation about currentBuild.previousBuild? I can't find this documentationGabriel Oliveira
@GabrielOliveira: It is under http://<your-jenkins-server>/pipeline-syntax/globalsFuzzY
thanks @FuzzY! I checked this page earlier but I think it was updated in some version.Gabriel Oliveira

1 Answers

24
votes

currentBuild.rawBuild will give you the non cached hudson.model.Run object, see hudson.model.Run

from there, to access i.e. the build log:

def buildLog = currentBuild.rawBuild.log

currentBuild.rawBuild is also of type hudson.model.AbstractBuild which can give you other details like changeset, actions