Class: Fastlane::Actions::BitriseAction
- Inherits:
-
Action
- Object
- Action
- Fastlane::Actions::BitriseAction
- Defined in:
- lib/fastlane/plugin/bitrise/actions/bitrise_action.rb
Class Method Summary collapse
- .authors ⇒ Object
- .available_options ⇒ Object
- .description ⇒ Object
- .details ⇒ Object
-
.get_environments_from(params) ⇒ Object
Transform environments variable hash into dictionary objects.
-
.get_post_payload(trigger_token, workflow, author, build_message, branch, commit, tag, environments) ⇒ Object
Get POST payload json.
- .is_supported?(platform) ⇒ Boolean
- .return_value ⇒ Object
- .run(params) ⇒ Object
-
.trigger_bitrise_build(app_slug, json) ⇒ Object
Call the Bitrise.io API with a POST HTTP request with the specified payload.
Class Method Details
.authors ⇒ Object
145 146 147 |
# File 'lib/fastlane/plugin/bitrise/actions/bitrise_action.rb', line 145 def self. ["Robin AUTHIAT"] end |
.available_options ⇒ Object
157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 |
# File 'lib/fastlane/plugin/bitrise/actions/bitrise_action.rb', line 157 def self. [ # App specific parameters FastlaneCore::ConfigItem.new(key: :app_slug, env_name: "BITRISE_APP_SLUG", description: "Bitrise application slug, avalaible on bitrise.io > your app > code", optional: false, type: String, verify_block: proc do |value| UI.user_error!("No Bitrise app slug given, pass it using `app_slug` parameter to the bitrise plugin.") unless value && !value.empty? end), FastlaneCore::ConfigItem.new(key: :trigger_token, env_name: "BITRISE_TRIGGER_TOKEN", description: "Bitrise build trigger token, avalaible on bitrise.io > your app > code", optional: false, type: String, verify_block: proc do |value| UI.user_error!("No Bitrise trigger token given, pass it using `trigger_token` parameter to the bitrise plugin.") unless value && !value.empty? end), # Bitrise.io specific parameters FastlaneCore::ConfigItem.new(key: :workflow, env_name: "BITRISE_WORKFLOW", description: "Bitrise workflow to trigger, if not specified, it'll trigger the default one", optional: true, type: String, verify_block: proc do |value| UI.user_error!("Empty Bitrise workflow given, pass it using `workflow` parameter to the bitrise plugin.") unless value && !value.empty? end), FastlaneCore::ConfigItem.new(key: :build_message, env_name: "BITRISE_BUILD_MESSAGE", description: "Build message who'll appear on Bitrise.io build", optional: true, type: String), FastlaneCore::ConfigItem.new(key: :author, env_name: "BITRISE_AUTHOR", description: "Desribe who triggered the build it'll appear on Bitrise.io build", optional: true, type: String), FastlaneCore::ConfigItem.new(key: :environments, description: "Bitrise environments to replace, it'll override the previous environment variables specified. The Hash key has to be the environment variable key (without the $), the Hash value has to be environment variable value", optional: true, type: Hash, verify_block: proc do |value| value.each do |key| UI.user_error!("Please remove the '$' from the environment variable #{key}") if key.to_s.include?("$") end end), # Git related parameters FastlaneCore::ConfigItem.new(key: :branch, env_name: "BITRISE_GIT_BRANCH", description: "Git branch where to trigger bitrise workflow", optional: true, type: String, verify_block: proc do |value| UI.user_error!("Empty Bitrise git branch given, pass it using `branch` parameter to the bitrise plugin.") unless value && !value.empty? end), FastlaneCore::ConfigItem.new(key: :commit, env_name: "BITRISE_GIT_COMMIT", description: "Specific Git commit to trigger bitrise workflow", optional: true, type: String, verify_block: proc do |value| UI.user_error!("Empty Bitrise git commit given, pass it using `commit` parameter to the bitrise plugin.") unless value && !value.empty? end), FastlaneCore::ConfigItem.new(key: :tag, env_name: "BITRISE_GIT_TAG", description: "Specific Git tag to trigger bitrise workflow", optional: true, type: String, verify_block: proc do |value| UI.user_error!("Empty Bitrise git tag given, pass it using `tag` parameter to the bitrise plugin.") unless value && !value.empty? end) ] end |
.description ⇒ Object
141 142 143 |
# File 'lib/fastlane/plugin/bitrise/actions/bitrise_action.rb', line 141 def self.description "Trigger a bitrise build" end |
.details ⇒ Object
153 154 155 |
# File 'lib/fastlane/plugin/bitrise/actions/bitrise_action.rb', line 153 def self.details "This plugin allow you to trigger a specific Bitrise workflow with some arguments with a HTTPS POST on the Bitrise API." end |
.get_environments_from(params) ⇒ Object
Transform environments variable hash into dictionary objects
Parameters:
-
params: Environments hash to transform
Returns the environments objects array
87 88 89 90 91 92 93 94 95 96 97 98 99 100 |
# File 'lib/fastlane/plugin/bitrise/actions/bitrise_action.rb', line 87 def self.get_environments_from(params) environments = [] params.each do |key, value| environment = {} environment["mapped_to"] = key environment["value"] = value environment["is_expand"] = true environments.push(environment) end environments end |
.get_post_payload(trigger_token, workflow, author, build_message, branch, commit, tag, environments) ⇒ Object
Get POST payload json
Parameters:
-
trigger_token: Bitrise.io trigger token
-
workflow: Bitrise.io workflow to trigger (optional)
-
author: Describe who triggered the build
-
build_message: Build message on Bitrise.io (optional)
-
branch: Git branch to trigger (optional)
-
commit: Git commit to trigger (optional)
-
tag: Git tag to trigger (optional)
-
environments: Environments variables hash to replace (optional)
Returns the JSON post payload
37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 |
# File 'lib/fastlane/plugin/bitrise/actions/bitrise_action.rb', line 37 def self.get_post_payload(trigger_token, workflow, , , branch, commit, tag, environments) UI.("Payload creation...") json_curl = {} payload = {} hook_info = {} hook_info["type"] = "bitrise" hook_info["build_trigger_token"] = trigger_token payload["hook_info"] = hook_info unless .nil? payload["triggered_by"] = end build_params = {} unless workflow.nil? build_params["workflow_id"] = workflow end unless .nil? || .empty? build_params["commit_message"] = end unless branch.nil? build_params["branch"] = branch end unless commit.nil? build_params["commit_hash"] = commit end unless tag.nil? build_params["tag"] = tag end unless environments.nil? build_params["environments"] = get_environments_from(environments) end payload["build_params"] = build_params json_curl["payload"] = payload json_curl.to_json end |
.is_supported?(platform) ⇒ Boolean
232 233 234 |
# File 'lib/fastlane/plugin/bitrise/actions/bitrise_action.rb', line 232 def self.is_supported?(platform) true end |
.return_value ⇒ Object
149 150 151 |
# File 'lib/fastlane/plugin/bitrise/actions/bitrise_action.rb', line 149 def self.return_value "If the build could be triggered, it returns the build informations such as the bitrise build number and the bitrise build url in a Hash" end |
.run(params) ⇒ Object
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 |
# File 'lib/fastlane/plugin/bitrise/actions/bitrise_action.rb', line 7 def self.run(params) FastlaneCore::PrintTable.print_values(config: params.values(ask: false), hide_keys: [], title: "Bitrise options") json = get_post_payload(params[:trigger_token], params[:workflow], params[:author], params[:build_message], params[:branch], params[:commit], params[:tag], params[:environments]) trigger_bitrise_build(params[:app_slug], json) end |
.trigger_bitrise_build(app_slug, json) ⇒ Object
Call the Bitrise.io API with a POST HTTP request with the specified payload. It’ll throw an exception if the API return an other HTTP status code than 201.
Parameters:
-
app_slug: Application slug
-
json: request payload
108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 |
# File 'lib/fastlane/plugin/bitrise/actions/bitrise_action.rb', line 108 def self.trigger_bitrise_build(app_slug, json) UI.command(json) UI.("Requesting Bitrise.io API...") uri = URI.parse("https://app.bitrise.io/app/#{app_slug}/build/start.json") https = Net::HTTP.new(uri.host, uri.port) https.use_ssl = true request = Net::HTTP::Post.new(uri.path, { 'Content-Type' => 'application/json' }) request.body = json response = https.request(request) json_response = JSON.parse(response.body) FastlaneCore::PrintTable.print_values(config: json_response, hide_keys: [], title: "Bitrise API response") if response.code == "201" UI.success("Build triggered successfully on Bitrise.io 🚀") else if response.code == "400" error = json_response["message"] else error = json_response["error_msg"] end UI.user_error!("Couln't trigger the build on Bitrise.io. #{error}") end build_infos = {} build_infos["build_number"] = json_response["build_number"] build_infos["build_url"] = json_response["build_url"] build_infos end |