5

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

Tom Deseyn
  • 1,735
  • 3
  • 17
  • 29

3 Answers3

8

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.

mrooney
  • 1,994
  • 2
  • 19
  • 30
1

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.

  • couldn't get plugin to work because credentialsID didn't work w/ the latest Jenkins 2.x...they don't use a UUID any more. This was the simplest thing to do... – kenyee Aug 23 '16 at 13:53
  • Also note that the URL has to be in the format: https:///rest/build-status/1.0/commits/ – kenyee Aug 23 '16 at 13:53
0

Use the Stash Notifier by adding it as a Post Step in your Jenkins build job configuration.

In your Jenkins job configuration go to the Post-build Actions section, click on Add post-build action and select Notify Stash Instance Enter the Stash base URL, e. g. http://localhost:7990 or http://my.company/stash.

If in doubt, go to your local Stash server and check the URL in the browser. The URL http://georg@localhost:7991/projects e. g. reveals the server base URL, which is http://localhost:7991 in this case. Use the Credentials Plugin to select credentials for stash.

Abhijeet Kamble
  • 3,131
  • 2
  • 30
  • 36
  • 1
    As I put in my question: "The configuration page does not have a 'Post-build Actions section'." Does your Jenkins 2 multibranch pipeline have such a section? – Tom Deseyn May 11 '16 at 13:00
  • this only works if you use a standard jenkins job...the question was how to do it w/ pipeline and I think you have to be able to call the plugin as a step. – kenyee Aug 20 '16 at 02:39