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\"}" |
Very helpful... thank you!!!
thank you guys 👍
hi thanks,
but i dont undertsand this url : "https://api.github.com/repos/justincampbell/my_repo/statuses/$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
$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 https://wiki.jenkins.io/display/JENKINS/Building+a+software+project for more information.
the after.sh 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?
@jholovacs I had same issue. Just tried this plugin and it works fine. https://wiki.jenkins.io/display/JENKINS/Conditional+BuildStep+Plugin
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
- curl 'https://api.GitHub.com/repos/user_name/repo_name/statuses/255dff7b4ccb35213203174fc3f4106cbaa2b75e?access_token=toke_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/6/console"}'
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
0 0 0 0 0 0 0 0 --:--:-- --:--:-- --:--:-- 0
100 303 100 119 100 184 485 750 --:--:-- --:--:-- --:--:-- 751
{
"message": "Not Found",
"documentation_url": "https://developer.github.com/v3/repos/statuses/#create-a-status"
}
POST BUILD TASK : SUCCESS
END OF POST BUILD TASK : 0
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' "
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\",