Skip to content

Instantly share code, notes, and snippets.

@keo
Created October 29, 2012 10:30
Show Gist options
  • Save keo/3972842 to your computer and use it in GitHub Desktop.
Save keo/3972842 to your computer and use it in GitHub Desktop.
Post TeamCity build status to GitHub
#!/usr/bin/env ruby
require 'bundler/setup'
require 'rest-client'
require 'json'
teamcity_url = ENV['TEAMCITY_URL']
build_num = ENV['BUILD_NUMBER']
build_type = ENV['BUILD_TYPE']
github_token = ENV['GITHUB_TOKEN']
github_repo = ENV['GITHUB_REPO']
unless (teamcity_url and build_num and build_type and github_token and github_repo)
puts "please specify TEAMCITY_URL, BUILD_NUMBER, BUILD_TYPE, GITHUB_REPO and GITHUB_TOKEN environment variables"
exit 1
end
tc_url = "#{teamcity_url}httpAuth/app/rest/builds/buildType:#{build_type},number:#{build_num}"
res = JSON.parse(RestClient.get(tc_url, accept: :json))
commit_sha = res["revisions"]["revision"].first["version"]
post_data = { state: res["status"].downcase,
target_url: res["webUrl"],
description: res["statusText"]
}
gh_url = "https://api.github.com/repos/#{github_repo}/statuses/#{commit_sha}"
puts RestClient.post gh_url, post_data.to_json, { content_type: :json, authorization: "token #{github_token}" }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment