Skip to content

Instantly share code, notes, and snippets.

@justincampbell
Created March 1, 2013 17:45
Show Gist options
  • Star 68 You must be signed in to star a gist
  • Fork 14 You must be signed in to fork a gist
  • Save justincampbell/5066394 to your computer and use it in GitHub Desktop.
Save justincampbell/5066394 to your computer and use it in GitHub Desktop.
Jenkins + GitHub Commit Status API
if [[ $BUILD_STATUS == "success" ]]
then
export STATUS="success"
else
export STATUS="failure"
fi
curl "https://api.github.com/repos/justincampbell/my_repo/statuses/$GIT_COMMIT?access_token=abc123" \
-H "Content-Type: application/json" \
-X POST \
-d "{\"state\": \"$STATUS\", \"description\": \"Jenkins\", \"target_url\": \"http://my.jenkins.box.com/job/dividata/$BUILD_NUMBER/console\"}"
curl "https://api.github.com/repos/justincampbell/my_repo/statuses/$GIT_COMMIT?access_token=abc123" \
-H "Content-Type: application/json" \
-X POST \
-d "{\"state\": \"pending\", \"description\": \"Jenkins\", \"target_url\": \"http://my.jenkins.box.com/job/dividata/$BUILD_NUMBER/console\"}"
@jurosh
Copy link

jurosh commented Jun 20, 2018

@jholovacs I had same issue. Just tried this plugin and it works fine. https://wiki.jenkins.io/display/JENKINS/Conditional+BuildStep+Plugin

@jason-evt
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 "https://api.GitHub.com/repos/user_name/repo_name/statuses/$GIT_COMMIT?access_token=token_value"
-H "Content-Type: application/json"
-X POST
-d "{"state": "success","context": "continuous-integration/jenkins", "description": "Jenkins", "target_url": "http://jenkins-mobile-01.example.net:8080/job/github-status-test/$BUILD_NUMBER/console\"}"
[github-status-test] $ /bin/sh -xe /var/folders/5f/f_9_4ncj4550bzyrg0vmzw8h00008b/T/jenkins131952762425065348.sh

@sperry
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

https://developer.github.com/changes/2020-02-10-deprecating-auth-through-query-param/

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