Skip to content

Instantly share code, notes, and snippets.

@brookslyrette
Created November 14, 2015 16:03
Show Gist options
  • Save brookslyrette/36e2392208c8ff590985 to your computer and use it in GitHub Desktop.
Save brookslyrette/36e2392208c8ff590985 to your computer and use it in GitHub Desktop.
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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment