Class: Fastlane::Actions::TriggerBitriseWorkflowAction
- Inherits:
-
Action
- Object
- Action
- Fastlane::Actions::TriggerBitriseWorkflowAction
- Defined in:
- lib/fastlane/plugin/bitrise_automation/actions/trigger_bitrise_workflow_action.rb
Class Method Summary collapse
- .authors ⇒ Object
- .available_options ⇒ Object
- .description ⇒ Object
- .is_supported?(platform) ⇒ Boolean
- .return_value ⇒ Object
- .run(params) ⇒ Object
- .wait_until_build_completion(params, build_slug) ⇒ Object
Class Method Details
.authors ⇒ Object
84 85 86 |
# File 'lib/fastlane/plugin/bitrise_automation/actions/trigger_bitrise_workflow_action.rb', line 84 def self. ["Mario Cecchi", "Henrique Alves"] end |
.available_options ⇒ Object
92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 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 140 141 142 |
# File 'lib/fastlane/plugin/bitrise_automation/actions/trigger_bitrise_workflow_action.rb', line 92 def self. [ FastlaneCore::ConfigItem.new(key: :app_slug, env_name: "BITRISE_APP_SLUG", description: "The app slug of the project on Bitrise", optional: false, type: String), FastlaneCore::ConfigItem.new(key: :access_token, env_name: "BITRISE_ACCESS_TOKEN", description: "The personal access token used to call Bitrise API", optional: false, type: String), FastlaneCore::ConfigItem.new(key: :workflow, env_name: "BITRISE_WORKFLOW", description: "The name of the workflow to trigger", optional: false, type: String), FastlaneCore::ConfigItem.new(key: :branch, env_name: "BITRISE_BUILD_BRANCH", description: "The name of branch that will be checked out", optional: true, type: String), FastlaneCore::ConfigItem.new(key: :commit_hash, env_name: "BITRISE_BUILD_COMMIT_HASH", description: "The hash of the commit that will be checked out", optional: true, type: String), FastlaneCore::ConfigItem.new(key: :build_message, env_name: "BITRISE_BUILD_MESSAGE", description: "A custom message that will be used to identify the build", optional: true, type: String), FastlaneCore::ConfigItem.new(key: :triggered_by, env_name: "BITRISE_BUILD_TRIGGERED_BY", description: "A custom message that will be used to identify where the build was triggered from", optional: true, type: String), FastlaneCore::ConfigItem.new(key: :wait_for_build, env_name: "BITRISE_WAIT_FOR_BUILD", description: "Whether the action should wait until the build finishes or return immediately after requesting the build", optional: true, default_value: false, is_string: false), FastlaneCore::ConfigItem.new(key: :download_artifacts, env_name: "BITRISE_DOWNLOAD_ARTIFACTS", description: "Whether to download or not the produced artifacts", optional: true, default_value: false, is_string: false) ] end |
.description ⇒ Object
80 81 82 |
# File 'lib/fastlane/plugin/bitrise_automation/actions/trigger_bitrise_workflow_action.rb', line 80 def self.description "Trigger a Bitrise workflow with the specified parameters, synchronously or asynchronously" end |
.is_supported?(platform) ⇒ Boolean
144 145 146 |
# File 'lib/fastlane/plugin/bitrise_automation/actions/trigger_bitrise_workflow_action.rb', line 144 def self.is_supported?(platform) true end |
.return_value ⇒ Object
88 89 90 |
# File 'lib/fastlane/plugin/bitrise_automation/actions/trigger_bitrise_workflow_action.rb', line 88 def self.return_value "Returns the information of the Bitrise build" end |
.run(params) ⇒ Object
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 |
# File 'lib/fastlane/plugin/bitrise_automation/actions/trigger_bitrise_workflow_action.rb', line 7 def self.run(params) UI.("Requesting new Bitrise.io build for workflow '#{params[:workflow]}'...") trigger_payload = { hook_info: { type: "bitrise" }, build_params: { workflow_id: params[:workflow] } } trigger_payload[:build_params][:branch] = params[:branch] unless params[:branch].nil? || params[:branch].empty? trigger_payload[:build_params][:commit_hash] = params[:commit_hash] unless params[:commit_hash].nil? || params[:commit_hash].empty? trigger_payload[:build_params][:commit_message] = params[:build_message] unless params[:build_message].nil? || params[:build_message].empty? trigger_payload[:triggered_by] = params[:triggered_by] unless params[:triggered_by].nil? || params[:triggered_by].empty? response = Helper::BitriseRequestHelper.post(params, 'builds', trigger_payload.to_json) if response.code == "201" json_response = JSON.parse(response.body) UI.success("Build #{json_response['build_number']} triggered successfully on Bitrise 🚀 URL: #{json_response['build_url']}") FastlaneCore::PrintTable.print_values(config: json_response, title: "Bitrise API response") else UI.crash!("Error requesting new build on Bitrise.io. Status code: #{response.code}. #{response.body}") end build_infos = {} build_infos["status"] = json_response["status"] build_infos["build_url"] = json_response["build_url"] build_infos["build_number"] = json_response["build_number"] build_infos["build_slug"] = json_response["build_slug"] if params[:wait_for_build] build_status = wait_until_build_completion(params, build_infos["build_slug"]) if params[:download_artifacts] BitriseBuildArtifactsAction.get_artifacts(params, build_infos["build_slug"]) end build_infos["status"] = build_status["status_text"] if build_status["status"] == 1 UI.success("Build has finished successfully on Bitrise!") elsif build_status["status"] == 2 UI.build_failure!("Build has FAILED on Bitrise. Check more details at #{build_infos['build_url']}.") elsif build_status["status"] == 3 || build_status["status"] == 4 UI.build_failure!("Build has been ABORTED on Bitrise. Abort reason: '#{build_status['abort_reason']}'. Check more details at #{build_infos['build_url']}.") else UI.build_failure!("Build has ended with unknown status on Bitrise: #{build_status}. Check more details at #{build_infos['build_url']}.") end end build_infos end |
.wait_until_build_completion(params, build_slug) ⇒ Object
62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 |
# File 'lib/fastlane/plugin/bitrise_automation/actions/trigger_bitrise_workflow_action.rb', line 62 def self.wait_until_build_completion(params, build_slug) build_status = {} loop do build_status = BitriseBuildStatusAction.get_status(params, build_slug) break if build_status['status'] != 0 if build_status['is_on_hold'] UI.("Build is still on hold. Sleeping...") else UI.("Build is running with status '#{build_status['status_text']}'. Sleeping...") end sleep(30) end build_status end |