Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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
@Kamilius

This comment has been minimized.

Copy link

Kamilius commented Jul 25, 2017

Any tips on where to put those scripts, so they would start working? A quick installation guide would be awesome

@pcolmer

This comment has been minimized.

Copy link

pcolmer commented Jan 16, 2018

@Kamilius See https://blog.oyanglul.us/make%20bamboo%20support%20github%20pull%20request%20with%20status%20api - these scripts are basically run as part of a Bamboo build plan.

@siddharth-kapoor

This comment has been minimized.

Copy link

siddharth-kapoor commented May 22, 2018

Hi, I'm trying to follow link https://blog.oyanglul.us/make%20bamboo%20support%20github%20pull%20request%20with%20status%20api and got stuck at executing Hubot script. When I start Hubot, I'm getting following error from script. Please see below complete logs once I run ./bin/hubot.. Also I have added contents of package.json, external-files.json, and script used (whitespaces trimmed). Can you please help?


npm WARN hubot-help@0.2.2 requires a peer of coffee-script@^1.12.6 but none is installed. You must install peer dependencies yourself.

up to date in 1.244s
[!] 21 vulnerabilities found [266 packages audited]
Severity: 11 Low | 2 Moderate | 8 High
Run npm audit for more detail

Sid_Hubot> [Tue May 22 2018 03:05:32 GMT+0000 (UTC)] ERROR Unable to load /home/ubuntu/myhubot/scripts/hubot-bamboo-pr: /home/ubuntu/myhubot/scripts/hubot-bamboo-pr.coffee:12:1: error: unexpected if
if eventType in eventTypes
^^

Package.json

{
"name": "Sid_Hubot",
"version": "0.0.0",
"private": true,
"author": "Sid Kapoor s@kapoor.com",
"description": "Delightfully aware robutt",
"dependencies": {
"coffeescript": "^1.6.2",
"hubot": "^2.19.0",
"hubot-bamboo-pr": "^1.0.1",
"hubot-diagnostics": "0.0.2",
"hubot-google-images": "^0.2.7",
"hubot-google-translate": "^0.2.1",
"hubot-help": "^0.2.2",
"hubot-heroku-keepalive": "^1.0.3",
"hubot-maps": "0.0.3",
"hubot-pugme": "^0.1.1",
"hubot-redis-brain": "0.0.4",
"hubot-rules": "^0.1.2",
"hubot-scripts": "^2.17.2",
"hubot-shipit": "^0.2.1"
},
"engines": {
"node": "0.10.x"
}
}

External-files.json

[
"hubot-diagnostics",
"hubot-help",
"hubot-heroku-keepalive",
"hubot-google-images",
"hubot-google-translate",
"hubot-pugme",
"hubot-maps",
"hubot-redis-brain",
"hubot-rules",
"hubot-shipit",
"hubot-bamboo-pr"
]

Script:

module.exports = (robot) ->
robot.router.post "/hubot/trigger-bamboo", (req, res) ->
query = querystring.parse(url.parse(req.url).query)
bamboo_url = query.bamboo
build_key = query.buildKey
room = query.room
res.end "" if !bamboo_url || !room
data = req.body
eventType = req.headers["x-github-event"]
console.log "Processing event type #{eventType}..."
try
if eventType in eventTypes
robot.http("#{bamboo_url}/rest/api/latest/queue/#{build_key}?bamboo.variable.pull_sha=#{data.pull_request.head.sha}&bamboo.variable.pull_num=#{data.number}") (post-bamboo-api).post()

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.
You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session.