module NG1BuildHelpers::CircleCI
Constants
- Options
Public Class Methods
commandline_fetch_commit_range(args = nil)
click to toggle source
# File lib/circleci/circleci.rb, line 135 def self.commandline_fetch_commit_range(args = nil) if !ENV["CIRCLECI"] puts("Not running on CircleCI") return end options = OptionsParser.parse(args) fetch_commit_range(options) end
fetch_commit_range(options)
click to toggle source
# File lib/circleci/circleci.rb, line 113 def self.fetch_commit_range(options) start_revision = ENV["CIRCLE_SHA1"] begin end_revision = nil while end_revision == nil && options.branch.length > 0 do check_branch = options.branch end_revision = get_last_successful_rev(options, check_branch) end put_range(options, start_revision, end_revision) rescue RestClient::Exception => e puts "ERROR getting last successful build from CircleCI" exit 1 end end
get_last_successful_rev(options, branch)
click to toggle source
Using CircleCI
API go through to find the last successful build for a specified branch and grab the revision.
# File lib/circleci/circleci.rb, line 80 def self.get_last_successful_rev(options, branch) headers = { "Accept" => "application/json" } end_revision = nil circle_token = options.token if (!circle_token) circle_token = ENV["CIRCLE_TOKEN"] if (!circle_token) puts("Problem getting last successful revision, make sure the CircleCI Token is set") end end full_url = "#{options.url}/project/github/#{options.company}/#{options.project}/tree/#{options.branch}?circle-token=#{circle_token}" response = RestClient.get(full_url, headers=headers) json_response = JSON.parse(response.body) json_response.each do |build| compare = build["compare"] if (compare) # Get the compare last path. This will look # something like 'f6fb62c25d4c...39f49d7ca2af' revisions = compare.split('/')[-1] # Take the first revision and use this as the end end_revision = revisions.partition("...")[0] break end end return end_revision end
print_help()
click to toggle source
# File lib/circleci/circleci.rb, line 131 def self.print_help() OptionsParser.parse(["--help"]) end
put_range(options, start_revision, end_revision)
click to toggle source
If run with the export option, this will set the environment variable that the JIRA
scripts will use to determine which new stories were completed
# File lib/circleci/circleci.rb, line 62 def self.put_range(options, start_revision, end_revision) value = "" if end_revision value = "#{end_revision}..#{start_revision}" else value = "#{start_revision}" end if options.export puts value else puts "##circleci[setParameter name='env.CIRCLECI_COMMIT_RANGE' value='#{value}']" end end