Created
August 17, 2016 16:06
-
-
Save donnoman/3d439351c5fe57143fe2ad829b122648 to your computer and use it in GitHub Desktop.
Buildkite v2 API Build Trigger Script
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env ruby | |
require "bundler" | |
Bundler.setup | |
require "httparty" | |
unless ENV["BUILDKITE_KEY"] | |
puts "you need to set your BUILDKITE_KEY" | |
exit 1 | |
end | |
def buildkite_key | |
ENV["BUILDKITE_KEY"] | |
end | |
def variant | |
ARGV[0] ? ARGV[0] : "staging" | |
end | |
def headers | |
{ "Authorization" => "Bearer #{buildkite_key}" } | |
end | |
def body | |
{ | |
commit: "HEAD", | |
branch: "master", | |
message: "Triggered :robot_face: db-prod-to-staging for #{variant}", | |
env: { | |
"TASK" => "db-prod-to-staging", | |
"VARIANT" => variant | |
} | |
} | |
end | |
def request | |
HTTParty.post( | |
"https://api.buildkite.com/v2/organizations/YOUR_ORG/pipelines/YOUR_PIPELINE/builds", | |
headers: headers, | |
:body => body.to_json | |
) | |
end | |
def response | |
request.parsed_response | |
end | |
puts response['jobs'].to_yaml |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment