Module: NG1BuildHelpers::CircleCI
- Defined in:
- lib/circleci/circleci.rb
Defined Under Namespace
Classes: Options, OptionsParser
Class Method Summary collapse
- .commandline_fetch_commit_range(args = nil) ⇒ Object
- .fetch_commit_range(options) ⇒ Object
-
.get_last_successful_rev(options, branch) ⇒ Object
Using CircleCI API go through to find the last successful build for a specified branch and grab the revision.
- .print_help ⇒ Object
-
.put_range(options, start_revision, end_revision) ⇒ Object
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.
Class Method Details
.commandline_fetch_commit_range(args = nil) ⇒ Object
135 136 137 138 139 140 141 142 |
# 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 = OptionsParser.parse(args) fetch_commit_range() end |
.fetch_commit_range(options) ⇒ Object
113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 |
# File 'lib/circleci/circleci.rb', line 113 def self.fetch_commit_range() start_revision = ENV["CIRCLE_SHA1"] begin end_revision = nil while end_revision == nil && .branch.length > 0 do check_branch = .branch end_revision = get_last_successful_rev(, check_branch) end put_range(, 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) ⇒ Object
Using CircleCI API go through to find the last successful build for a specified branch and grab the revision.
80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 |
# File 'lib/circleci/circleci.rb', line 80 def self.get_last_successful_rev(, branch) headers = { "Accept" => "application/json" } end_revision = nil circle_token = .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 = "#{.url}/project/github/#{.company}/#{.project}/tree/#{.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 ⇒ Object
131 132 133 |
# File 'lib/circleci/circleci.rb', line 131 def self.print_help() OptionsParser.parse(["--help"]) end |
.put_range(options, start_revision, end_revision) ⇒ Object
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
62 63 64 65 66 67 68 69 70 71 72 73 74 75 |
# File 'lib/circleci/circleci.rb', line 62 def self.put_range(, start_revision, end_revision) value = "" if end_revision value = "#{end_revision}..#{start_revision}" else value = "#{start_revision}" end if .export puts value else puts "##circleci[setParameter name='env.CIRCLECI_COMMIT_RANGE' value='#{value}']" end end |