GithubHelp home page GithubHelp logo

foneox / stashnotifier-plugin Goto Github PK

View Code? Open in Web Editor NEW

This project forked from jenkinsci/stashnotifier-plugin

0.0 2.0 0.0 426 KB

A Jenkins Plugin to notify Atlassian Stash|Bitbucket of build results

Home Page: https://wiki.jenkins.io/display/JENKINS/Bitbucket+%28Stash%29+Notifier+Plugin

License: Other

Java 97.13% HTML 2.87%

stashnotifier-plugin's Introduction

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. You must set the result of the current build manually in the Pipeline script.

node {
    checkout scm                            // Necessary so we know the current commit

    notifyBitbucket()                       // 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!
    }

    notifyBitbucket()                       // Notifies the Stash Instance of the build result
}

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

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

def notifyBitbucket(String state) {

    if('SUCCESS' == state || 'FAILED' == state) {
        currentBuild.result = state         // Set result of currentBuild !Important!
    }
    notifyBitbucket commitSha1: "commit", 
                credentialsId: '00000000-1111-2222-3333-123456789abc', 
                disableInprogressNotification: false, 
                considerUnstableAsSuccess: true, 
                ignoreUnverifiedSSLPeer: true, 
                includeBuildNumberInKey: false, 
                prependParentProjectKey: false, 
                projectKey: '', 
                stashServerBaseUrl: 'https://stash.company.com'

}

In Declarative Pipelines, where Jenkins sets currentBuild.result = null for SUCCESS builds, the current value can be modified via a script step, e.g.:

pipeline {
    agent any
    stages {
        stage('Build') {
            steps {
                echo 'Hello World'
                // currentBuild.result == null here
            }
        }
    }
    post { 
        always { 
            script {
                currentBuild.result = currentBuild.result ?: 'SUCCESS'
                notifyBitbucket()
            }
        }
    }
}

Note on credentials

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

Maintainers

License

Apache 2.0 License

stashnotifier-plugin's People

Contributors

aaronjwood avatar ashnazg avatar bbaetz avatar colmelvin avatar cyburs avatar djaara avatar fvogler avatar gruetter avatar htanjo avatar johnjohndoe avatar klieber avatar lakritzator avatar lucamilanesio avatar lukasniemeier-zalando avatar markshead avatar mckramer avatar mdkf avatar nemccarthy avatar penland365 avatar phallstedt avatar plnordquist avatar pongells avatar reftel avatar rhysm avatar scaytrase avatar sdmoralesma avatar tandrup avatar thomaseizinger avatar vassilevsky avatar wilfred avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.