Created
February 12, 2018 01:55
-
-
Save TJC/45a4c31621b5d70b858e481852cb730d to your computer and use it in GitHub Desktop.
Trigger a buildkite rebuild of current branch
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 'json' | |
| require 'uri' | |
| require 'net/http' | |
| def get_git_branch | |
| `git rev-parse --abbrev-ref HEAD`.strip | |
| end | |
| def get_git_name | |
| `git config --get user.name`.strip | |
| end | |
| def get_git_email | |
| `git config --get user.email`.strip | |
| end | |
| job_spec = JSON.generate({ | |
| message: "10 retry build 20 goto 10", | |
| branch: get_git_branch, | |
| commit: "HEAD", | |
| author: { | |
| name: get_git_name, | |
| email: get_git_email | |
| } | |
| }) | |
| api_key = ENV["BK_API_KEY"] | |
| org = ENV["ORG_ID"] | |
| pipeline = ENV["PIPELINE_NAME"] | |
| uri = URI.parse("https://api.buildkite.com/v2/organizations/#{org}/pipelines/#{pipeline}/builds") | |
| request = Net::HTTP::Post.new(uri) | |
| request.content_type = "text/json" | |
| request.body = job_spec | |
| request["Authorization"] = "Bearer #{api_key}" | |
| response = Net::HTTP.start(uri.host, uri.port, :use_ssl => true) do |http| | |
| http.request(request) | |
| end | |
| puts(response.body) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment