{{tag>[github atlassian bamboo]}} ====== Set Github status from Bamboo ====== ===== Generate API access token from your Github ===== //Profile > Developer Settings > Pesonal Access tokens// ===== Use curl to update the status ===== curl -H "Authorization: token "" --request POST --data '{"state": "pending", "context": "build", "description": "Build is running", "target_url": "${bamboo.buildResultsUrl}"}' https://api.github.com/repos///statuses/${bamboo.repository.revision.number} > /dev/null For end task add something like grepping through the logs and report the status to github. See #!/bin/bash cd ${bamboo.build.working.directory} if ls **/test-results/*.xml 1> /dev/null 2>&1; then curl -H "Authorization: token " --request POST --data '{"state": "success", "context": "build", "description": "Build Passed", "target_url": "${bamboo.buildResultsUrl}"}' https://api.github.com/repos///statuses/${bamboo.repository.revision.number} > /dev/null else curl -H "Authorization: token " --request POST --data '{"state": "failure", "context": "build", "description": "Build Failed!", "target_url": "${bamboo.buildResultsUrl}"}' https://api.github.com/repos///statuses/${bamboo.repository.revision.number} > /dev/null fi ##check for test failures. if (grep 'failure message' **/test-results/*.xml 1> /dev/null 2>&1) then mainJunit=$(find **/test-results/*.xml -print0 | xargs -0 grep 'failure message' | wc -l) curl -H "Authorization: token " --request POST --data '{"state": "failure", "context": "tests", "description": "'"${mainJunit}"' Test(s) failed!", "target_url": "${bamboo.buildResultsUrl}"}' https://api.github.com/repos///statuses/${bamboo.repository.revision.number} > /dev/null else curl -H "Authorization: token " --request POST --data '{"state": "success", "context": "tests", "description": "Tests Passed", "target_url": "${bamboo.buildResultsUrl}"}' https://api.github.com/repos///statuses/${bamboo.repository.revision.number} > /dev/null fi #check for findbugs warnings if (grep 'BugInstance' **/reports/findbugs/*.xml 1> /dev/null 2>&1) then mainFb=$(grep -c 'BugInstance' **/reports/findbugs/main.xml) testFb=$(grep -c 'BugInstance' **/reports/findbugs/test.xml) sumFB=$(($mainFb+$testFb/2)) curl -H "Authorization: token " --request POST --data '{"state": "failure", "context": "findbugs", "description": "FindBugs found '"${sumFB}"' issues!", "target_url": "${bamboo.buildResultsUrl}"}' https://api.github.com/repos///statuses/${bamboo.repository.revision.number} > /dev/null else curl -H "Authorization: token " --request POST --data '{"state": "success", "context": "findbugs", "description": "FindBugs Passed", "target_url": "${bamboo.buildResultsUrl}"}' https://api.github.com/repos///statuses/${bamboo.repository.revision.number} > /dev/null fi #check for checkstyle warnings if (grep 'error' **/reports/checkstyle/*.xml 1> /dev/null 2>&1) then mainCs=$(grep -c 'error' **/reports/checkstyle/main.xml) testCs=$(grep -c 'error' **/reports/checkstyle/test.xml) sumCs=$(($mainCs+$testCs)) curl -H "Authorization: token " --request POST --data '{"state": "failure", "context": "checkstyle", "description": "Checkstyle found '"${sumCs}"' issues!", "target_url": "${bamboo.buildResultsUrl}"}' https://api.github.com/repos///statuses/${bamboo.repository.revision.number} > /dev/null else curl -H "Authorization: token " --request POST --data '{"state": "success", "context": "checkstyle", "description": "Checkstyle Passed", "target_url": "${bamboo.buildResultsUrl}"}' https://api.github.com/repos///statuses/${bamboo.repository.revision.number} > /dev/null fi ====== Tested on ====== ====== See also ====== ====== References ====== * https://rants.broonix.ca/updating-github-status-from-bamboo