htanjo / stashnotifier-plugin

A Jenkins Plugin to notify Atlassian Stash|Bitbucketof build results

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Stash Build Notifier Plugin for Jenkins

This Jenkins plugin notifies Stash of build results. Failed or successful builds will show up as little icons in the Stash web interface in commit logs. Clicking on such an icon will take the user to the specific build.

Requirements

  • Stash 2.1 or newer. This plugin uses the Atlassian Stash Build REST API which was introduced with Stash 2.1.
  • Jenkins 1.498 or newer

Setup

Set up Stash Notifier by navigating to Manage Jenkins --> Configure System and scrolling down to the Stash Notifier section. Enter at least your Stash Root Url and Credentials. Additional options are available as required. (Screenshot below is from Jenkins v2.44)

Stash Notifier Settings

Usage

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

  1. In your Jenkins job configuration go to the Post-build Actions section, click on Add post-build action and select Notify Stash Instance
  2. 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.
  3. Use the Credentials Plugin to select credentials for stash

That's it. If you have configured everything correctly, Jenkins will notify your Stash instance of subsequent builds. The result is illustrated on Atlassians Stash Build Integration wiki page.

Note on Pipeline Plugin usage

See the following code for an example of how to use this plugin inside of a [Pipeline Plugin] (https://wiki.jenkins-ci.org/display/JENKINS/Pipeline+Plugin). You must set the result of the current build manually in the Pipeline script.

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
}

In situations where an advanced setup is required the following can be used:

node {
    this.notifyStash('INPROGRESS')         // Notifies the Stash Instance of an INPROGRESS build
    
    try {
        // Do stuff
    
        this.notifyStash('SUCCESS')
    } catch(err) {
        this.notifyStash('FAILED')
    }
}

def notifyStash(String state) {

    if('SUCCESS' == state || 'FAILED' == state) {
        currentBuild.result = state         // Set result of currentBuild !Important!
    }

    step([$class: 'StashNotifier',
          commitSha1: "$commit",            // jenkins parameter that resolves to commit's hash
          credentialsId: '00000000-1111-2222-3333-123456789abc',
          disableInprogressNotification: false,
          ignoreUnverifiedSSLPeer: true,
          includeBuildNumberInKey: false,
          prependParentProjectKey: false,
          projectKey: '',
          stashServerBaseUrl: 'https://stash.company.com'])

}

Note on credentials

Currently Stash Build Notifier Plugin accepts only raw plaintext credentials as it work over HTTP REST API of stash

Maintainers

License

Apache 2.0 License

About

A Jenkins Plugin to notify Atlassian Stash|Bitbucketof build results

License:Other


Languages

Language:Java 97.1%Language:HTML 2.9%