Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions global-library-examples/notify-stash/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
This global function allows jenkins to notify stash of build status for a given commit. It uses the withCredentials and sh steps as well as curl to communicate with stash.
31 changes: 31 additions & 0 deletions global-library-examples/notify-stash/notifyStash.groovy
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
/**
* Notify stash of build status for commit
*
* @param status{String} INPROGRESS | SUCCESSFUL | FAILED
* @param message{String} Message to record in stash
* @param gitCommit{String} Full hash of git commit
*/
def call( status, message = "", gitCommit )
{
env.USERNAME = env.PASSWORD = ""

def postData = """{
"state": "$status",
"key": "$env.JOB_NAME #$env.BUILD_NUMBER",
"url": "$env.BUILD_URL",
"description": "Built by Jenkins: $message"
}"""

// CREDENTIAL_ID_IN_JENKINS should be replaced with your stash user credentials
// that have been stored in jenkins.

withCredentials([[$class: 'UsernamePasswordMultiBinding',
credentialsId: CREDENTIAL_ID_IN_JENKINS,
usernameVariable: 'USERNAME', passwordVariable: 'PASSWORD']])
{
def stashUrl = "https://YOUR_STASH_SERVER/rest/build-status/1.0/commits/$gitCommit"
def headers = "-H \"Content-Type: application/json\""
def credentials = "--user $env.USERNAME:$env.PASSWORD"
sh "curl $credentials $headers -X POST -d '$postData' $stashUrl"
}
}