Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Jenkins + GitHub Commit Status API
if [[ $BUILD_STATUS == "success" ]]
export STATUS="success"
export STATUS="failure"
curl "$GIT_COMMIT?access_token=abc123" \
-H "Content-Type: application/json" \
-d "{\"state\": \"$STATUS\", \"description\": \"Jenkins\", \"target_url\": \"$BUILD_NUMBER/console\"}"
curl "$GIT_COMMIT?access_token=abc123" \
-H "Content-Type: application/json" \
-d "{\"state\": \"pending\", \"description\": \"Jenkins\", \"target_url\": \"$BUILD_NUMBER/console\"}"
Copy link

You can set the context in the message payload to designate the different services that you might depend on for protection.
\"context\": \"continuous-integration/jenkins\",

Copy link

Very helpful... thank you!!!

Copy link

p00j4 commented Feb 23, 2017

thank you guys 👍

Copy link

hi thanks,
but i dont undertsand this url : "$GIT_COMMIT?access_token=abc123"
here you mentioned repo name,then what is statuses and $GIT_COMMIT variable value comes from? and what is targeturl in -d Section and $BUILD_NUMBER value carries what?
pls reply
thank you

Copy link

$GIT_COMMIT and $BUILD_NUMBER are Jenkins environment variables. The first is the git commit reference of the version of the branch that is being built - so unique reference to the exact commit being tested. The build number is the iteration of the jenkins job that was started in order to build the code.
See for more information.

Copy link

the is always coming back with a status of "failure" even when the build succeeds. Maybe the status isn't set by the point I'm running this? Where is this supposed to go?

Copy link

jurosh commented Jun 20, 2018

@jholovacs I had same issue. Just tried this plugin and it works fine.

Copy link

I got this error: "message" : "Not found". Anyone has any idea?
Note: Replaced valid values for user_name, repo_name, token_value when I executed the command

Running script : curl "$GIT_COMMIT?access_token=token_value"
-H "Content-Type: application/json"
-d "{"state": "success","context": "continuous-integration/jenkins", "description": "Jenkins", "target_url": "$BUILD_NUMBER/console\"}"
[github-status-test] $ /bin/sh -xe /var/folders/5f/f_9_4ncj4550bzyrg0vmzw8h00008b/T/

Copy link

sperry commented Jun 9, 2020

Please note upcoming (November 13, 2020 at 4:00 PM UTC) deprecation of API authentication using query parameters

Future users of this info will want to make following modifications to this gist:

  • Remove "?access_token=token_value" from URL
  • Add instead "-H 'Authorization: token token_value' "

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment