User Tools

Site Tools


wiki:set_github_status_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 "<your_githib_api_token>" --request POST --data '{"state": "pending", "context": "build", "description": "Build is running", "target_url": "${bamboo.buildResultsUrl}"}' https://api.github.com/repos/<username>/<repo_name>/statuses/${bamboo.repository.revision.number} > /dev/null

For end task add something like grepping through the logs and report the status to github. See

status_grep.sh
#!/bin/bash
cd ${bamboo.build.working.directory}
if ls **/test-results/*.xml 1> /dev/null 2>&1; then
  curl -H "Authorization: token <your_githib_api_token>" --request POST --data '{"state": "success", "context": "build", "description": "Build Passed", "target_url": "${bamboo.buildResultsUrl}"}' https://api.github.com/repos/<username>/<repo_name>/statuses/${bamboo.repository.revision.number} > /dev/null
else
  curl -H "Authorization: token <your_githib_api_token>" --request POST --data '{"state": "failure", "context": "build", "description": "Build Failed!", "target_url": "${bamboo.buildResultsUrl}"}' https://api.github.com/repos/<username>/<repo_name>/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 <your_githib_api_token>" --request POST --data '{"state": "failure", "context": "tests", "description": "'"${mainJunit}"' Test(s) failed!", "target_url": "${bamboo.buildResultsUrl}"}' https://api.github.com/repos/<username>/<repo_name>/statuses/${bamboo.repository.revision.number} > /dev/null
else
  curl -H "Authorization: token <your_githib_api_token>" --request POST --data '{"state": "success", "context": "tests", "description": "Tests Passed", "target_url": "${bamboo.buildResultsUrl}"}' https://api.github.com/repos/<username>/<repo_name>/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 <your_githib_api_token>" --request POST --data '{"state": "failure", "context": "findbugs", "description": "FindBugs found '"${sumFB}"' issues!", "target_url": "${bamboo.buildResultsUrl}"}' https://api.github.com/repos/<username>/<repo_name>/statuses/${bamboo.repository.revision.number} > /dev/null
else
  curl -H "Authorization: token <your_githib_api_token>" --request POST --data '{"state": "success", "context": "findbugs", "description": "FindBugs Passed", "target_url": "${bamboo.buildResultsUrl}"}' https://api.github.com/repos/<username>/<repo_name>/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 <your_githib_api_token>" --request POST --data '{"state": "failure", "context": "checkstyle", "description": "Checkstyle found '"${sumCs}"' issues!", "target_url": "${bamboo.buildResultsUrl}"}' https://api.github.com/repos/<username>/<repo_name>/statuses/${bamboo.repository.revision.number} > /dev/null
else
  curl -H "Authorization: token <your_githib_api_token>" --request POST --data '{"state": "success", "context": "checkstyle", "description": "Checkstyle Passed", "target_url": "${bamboo.buildResultsUrl}"}' https://api.github.com/repos/<username>/<repo_name>/statuses/${bamboo.repository.revision.number} > /dev/null
fi

Tested on

See also

References

wiki/set_github_status_bamboo.txt · Last modified: 2020/11/29 01:33 by antisa

Except where otherwise noted, content on this wiki is licensed under the following license: CC0 1.0 Universal
CC0 1.0 Universal Donate Powered by PHP Valid HTML5 Valid CSS Driven by DokuWiki