Multibranch job - configure post build groovy event in Jenkinsfile

322 views
Skip to first unread message

Mike

unread,
Jun 13, 2016, 2:52:31 PM6/13/16
to Jenkins Users
Hi,

I'm looking to try and setup a post build groovy script event with my Jenkinsfile for my multibranch job. Is this possible? I'm looking to try and update the build display name with the svn revision number used at the time of the build. This is the jenkinsfile script im using:

node()
{
 stage
'SVN'
 checkout scm
 stage
'Compile Win32'
 
//bat 'call make\\jenkins\\jenkins_build_win32.bat'
 stage
'Archive Artifacts'
 
//archive '_archive/**'
 stage
'Post Build'
 echo
'Result: ' + manager.build.result.toString()
 
//if (manager.build.getResult() == 'SUCCESS')
 
//{
 
def buildNum = manager.build.number
 
def buildRev = manager.build.envVars['SVN_REVISION']
 
def buildSvn = manager.build.envVars['SVN_URL']
 
def buildUrl = manager.build.envVars['BUILD_URL']
 
def buildLabel = manager.build.getDisplayName()
 echo
'Num: ' + buildNum + ' Rev: ' + buildRev + ' SVN Url: ' + buildSvn + ' URL: ' + buildUrl

 manager
.build.setDisplayName(buildLabel + ' - Revision: ')
 
//}


}


manager.build.result is always null. I imagine its because the build has not completed. both buildRev and buildSvn are also null at this time.

Any help would be appreciated.

Mike

Arnaud Héritier

unread,
Jun 21, 2016, 6:38:32 AM6/21/16
to jenkins...@googlegroups.com
Hi Mike,

  AFAIK currentBuild.result is never set automatically in pipeline jobs. You have to explicitly set it with something like

try {
  // do something
  currentBuild.result = 'SUCCESS'
} catch (Exception err) {
  currentBuild.result = 'FAILURE'
}

it may explain why it is null in your post build task

--
You received this message because you are subscribed to the Google Groups "Jenkins Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to jenkinsci-use...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/jenkinsci-users/8cd195b3-07c8-49fe-8df1-440b9a8294e0%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.



--
-----
Arnaud Héritier
Mail/GTalk: aheritier AT gmail DOT com
Twitter/Skype : aheritier

Antonio Muñiz

unread,
Jun 21, 2016, 6:58:55 AM6/21/16
to jenkins...@googlegroups.com
The build status is set normally as the build finishes successfully or not.

To explicitly control de status you can use `currentBuild.result` as Arnaud said. You can set de build display name by using `currentBuild.displayName='whatever'`.


For more options, visit https://groups.google.com/d/optout.



--
Antonio Muñiz
Software Engineer
CloudBees, Inc.

Reply all
Reply to author
Forward
0 new messages