Skip to content

Instantly share code, notes, and snippets.

@devdrops
Forked from jcouyang/Stop_build_if_PR.sh
Created May 26, 2016 11:40
Show Gist options
  • Save devdrops/bcfa0a56af0008c22efa740fcdc646fb to your computer and use it in GitHub Desktop.
Save devdrops/bcfa0a56af0008c22efa740fcdc646fb to your computer and use it in GitHub Desktop.
make Bamboo support Github Pull Request with Status API
#!/bin/bash
GITHUB_API=https://api.github.com
# if github enterprise https://your.github.domain/api/v3
if [[ -n ${bamboo_pull_num} ]]; then
echo "== send pending status =="
curl -H "Authorization: token $bamboo_GITHUB_STATUS_API_password" --request POST -k --data "{\"state\": \"pending\", \"description\": \"building...\", \"target_url\": \"$bamboo_resultsUrl\"}" https://$GITHUB_API/repos/the-money/condor/statuses/$bamboo_pull_sha > /dev/null
echo "git fetch PR $bamboo_pull_num =="
git fetch ${bamboo.repository.git.repositoryUrl} +refs/pull/$bamboo_pull_num/merge:
git checkout FETCH_HEAD
fi
#!/bin/bash
STATUS=$?
if [[ -n ${bamboo_pull_sha} ]]; then
if [ $STATUS != 0 ]; then
echo 'pull reqeust build failed'
curl -k -H "Authorization: token $bamboo_GITHUB_STATUS_API_password" --request POST --data "{\"state\": \"failure\", \"description\": \"failure:(\", \"target_url\": \"${bamboo.buildResultsUrl}\"}" $GITHUB_API/repos/:user/:repo/statuses/$bamboo_pull_sha > /dev/null
else
echo 'pull request build success'
curl -k -H "Authorization: token $bamboo_GITHUB_STATUS_API_password" --request POST --data "{\"state\": \"success\", \"description\": \"Success:)\", \"target_url\": \"${bamboo.buildResultsUrl}\"}" $GITHUB_API/repos/:user/:repo/statuses/$bamboo_pull_sha > /dev/null
fi
fi
#!/bin/bash
if [[ -n ${bamboo_pull_num} ]]; then
echo 'stoping bamboo'
curl "http://${bamboo_BAMBOO_USER}:${bamboo_BAMBOO_password}@your.bamboo.domain/build/admin/stopPlan.action?${bamboo.planResultKey}-${bamboo.buildNumber}"
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment