Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Use stash notifier plugin on Jenkins 2.0 multibranch pipeline

I don't know how to setup the stash notifier plugin on a multibranch pipeline. The configuration page does not have a 'Post-build Actions section'.

like image 738
Tom Deseyn Avatar asked May 11 '16 09:05

Tom Deseyn


2 Answers

Stash Notifier now supports Pipelines as of version 1.11.

From the examples in the README:

node {
    step([$class: 'StashNotifier'])         // Notifies the Stash Instance of an INPROGRESS build

    try {
        // Do stuff
        currentBuild.result = 'SUCCESS'     // Set result of currentBuild !Important!
    } catch(err) {
        currentBuild.result = 'FAILED'      // Set result of currentBuild !Important!
    }

    step([$class: 'StashNotifier'])         // Notifies the Stash Instance of the build result
}

While it says that setting currentBuild.result is "!Important!", my experience has been that this is only the case if your steps aren't already doing that. For example, if you have sh "false", you don't need to wrap that in a try/catch because the sh step will set the build result to failed on a non-zero exit code. This should only be necessary if you need custom success/failure logic.

like image 182
mrooney Avatar answered Nov 05 '22 07:11

mrooney


I think it is still not compatible with the pipeline or multibranch pipeline job type.

I think Abhijeet Kamble means that you can just use a http client or curl to send the updates yourself.

Something like this:

withCredentials([[$class          : 'UsernamePasswordMultiBinding', credentialsId: "$env.componentCredentialsId",
          usernameVariable: 'USERNAME', passwordVariable: 'PASSWORD']]) {
   writeFile file: 'build.json', text: "{\"state\": \"SUCCESSFUL\", \"key\": \"${env.JOB_NAME}\", \"name\": \"${env.BUILD_TAG}\", \"url\": \"${env.BUILD_URL}\"}"
   sh '''curl -u $USERNAME:$PASSWORD -H "Content-Type: application/json" -X POST $URL -d @build.json'''
}

Do note that it is a very simple example, not as sophisticated as the plugin.

like image 32
Joost van der Griendt Avatar answered Nov 05 '22 07:11

Joost van der Griendt