Class: Fastlane::Actions::BuildkiteTriggerBuildAction

Inherits:
Action
  • Object
show all
Defined in:
lib/fastlane/plugin/wpmreleasetoolkit/actions/common/buildkite_trigger_build_action.rb

Documentation collapse

Class Method Summary collapse

Class Method Details

.authorsObject



103
104
105
# File 'lib/fastlane/plugin/wpmreleasetoolkit/actions/common/buildkite_trigger_build_action.rb', line 103

def self.authors
  ['Automattic']
end

.available_optionsObject



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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
# File 'lib/fastlane/plugin/wpmreleasetoolkit/actions/common/buildkite_trigger_build_action.rb', line 50

def self.available_options
  [
    FastlaneCore::ConfigItem.new(
      key: :buildkite_token,
      env_names: %w[BUILDKITE_TOKEN BUILDKITE_API_TOKEN],
      description: 'Buildkite Personal Access Token',
      type: String,
      sensitive: true
    ),
    FastlaneCore::ConfigItem.new(
      key: :buildkite_organization,
      env_name: 'BUILDKITE_ORGANIZATION',
      description: 'The Buildkite organization that contains your pipeline',
      type: String
    ),
    FastlaneCore::ConfigItem.new(
      key: :buildkite_pipeline,
      env_name: 'BUILDKITE_PIPELINE',
      description: %(The Buildkite pipeline you'd like to build),
      type: String
    ),
    FastlaneCore::ConfigItem.new(
      key: :branch,
      description: 'The branch you want to build',
      type: String
    ),
    FastlaneCore::ConfigItem.new(
      key: :commit,
      description: 'The commit hash you want to build',
      type: String,
      default_value: 'HEAD'
    ),
    FastlaneCore::ConfigItem.new(
      key: :message,
      description: 'A custom message to show for the build in Buildkite\'s UI',
      type: String,
      optional: true,
      default_value: nil
    ),
    FastlaneCore::ConfigItem.new(
      key: :pipeline_file,
      description: 'The name of the pipeline file in the project',
      type: String
    ),
    FastlaneCore::ConfigItem.new(
      key: :environment,
      description: 'Any additional environment variables to provide to the job',
      type: Hash,
      default_value: {}
    ),
  ]
end

.descriptionObject



45
46
47
48
# File 'lib/fastlane/plugin/wpmreleasetoolkit/actions/common/buildkite_trigger_build_action.rb', line 45

def self.description
  # https://buildkite.com/docs/pipelines/glossary#build
  'Triggers a build on Buildkite'
end

.is_supported?(platform) ⇒ Boolean

Returns:

  • (Boolean)


111
112
113
# File 'lib/fastlane/plugin/wpmreleasetoolkit/actions/common/buildkite_trigger_build_action.rb', line 111

def self.is_supported?(platform)
  true
end

.return_valueObject



107
108
109
# File 'lib/fastlane/plugin/wpmreleasetoolkit/actions/common/buildkite_trigger_build_action.rb', line 107

def self.return_value
  'The web URL of the build the action started.'
end

.run(params) ⇒ Object



4
5
6
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
# File 'lib/fastlane/plugin/wpmreleasetoolkit/actions/common/buildkite_trigger_build_action.rb', line 4

def self.run(params)
  require 'buildkit'

  UI.message "Triggering build on branch #{params[:branch]}, commit #{params[:commit]}, using pipeline from #{params[:pipeline_file]}"

  pipeline_name = {
    PIPELINE: params[:pipeline_file]
  }
  options = {
    branch: params[:branch],
    commit: params[:commit],
    env: params[:environment].merge(pipeline_name),
    message: params[:message],
    # Buildkite will not trigger a build if the GitHub activity for that branch is turned off.
    # We want API triggers to work regardless of the GitHub activity settings, so this option is necessary.
    # See https://forum.buildkite.community/t/request-build-error-branches-have-been-disabled-for-this-pipeline/1463/2
    ignore_pipeline_branch_filters: true
  }.compact # remove entries with `nil` values from the Hash, if any

  client = Buildkit.new(token: params[:buildkite_token])
  response = client.create_build(
    params[:buildkite_organization],
    params[:buildkite_pipeline],
    options
  )

  build_url = response.web_url

  if response.state == 'scheduled'
    UI.success("Successfully scheduled new build. You can see it at '#{build_url}'")
  else
    UI.crash!("Failed to start build.\nError: [#{response}]")
  end

  build_url
end