Skip to content

Commit 48c9bc3

Browse files
committed
Fix pipeline upload error detection
1 parent e14bcf0 commit 48c9bc3

File tree

2 files changed

+22
-4
lines changed

2 files changed

+22
-4
lines changed

lib/fastlane/plugin/wpmreleasetoolkit/actions/common/buildkite_add_trigger_step_action.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,10 +38,10 @@ def self.run(params)
3838
}.to_yaml
3939

4040
# Use buildkite-agent to upload the pipeline
41-
_stdout, stderr, _status = Open3.capture3('buildkite-agent', 'pipeline', 'upload', stdin_data: trigger_yaml)
41+
_stdout, stderr, status = Open3.capture3('buildkite-agent', 'pipeline', 'upload', stdin_data: trigger_yaml)
4242

4343
# Check for errors
44-
UI.user_error!("Failed to upload pipeline: #{stderr}") unless stderr.empty?
44+
UI.user_error!("Failed to upload pipeline: #{stderr}") unless status.success?
4545

4646
# Log success
4747
UI.success("Added a trigger step to the current Buildkite build to start a new build for #{pipeline_file} on branch #{branch}")

spec/buildkite_add_trigger_step_action_spec.rb

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -130,8 +130,8 @@ def expected_yaml(
130130
end
131131
end
132132

133-
context 'when the pipeline upload fails' do
134-
it 'raises a user error with the error message' do
133+
context 'when pipeline upload errors' do
134+
it 'raises a user error when the command fails' do
135135
error_message = 'Failed to upload pipeline'
136136
allow(Open3).to receive(:capture3)
137137
.with('buildkite-agent', 'pipeline', 'upload', stdin_data: expected_yaml)
@@ -148,6 +148,24 @@ def expected_yaml(
148148
async: async
149149
)
150150
end
151+
152+
it 'does not error when the command succeeds, even with stderr output' do
153+
stderr_message = 'Some warning message'
154+
allow(Open3).to receive(:capture3)
155+
.with('buildkite-agent', 'pipeline', 'upload', stdin_data: expected_yaml)
156+
.and_return(['', stderr_message, instance_double(Process::Status, success?: true)])
157+
158+
expect(FastlaneCore::UI).not_to receive(:user_error!)
159+
160+
run_described_fastlane_action(
161+
pipeline_file: pipeline_file,
162+
branch: branch,
163+
message: message,
164+
environment: environment,
165+
buildkite_pipeline_slug: buildkite_pipeline_slug,
166+
async: async
167+
)
168+
end
151169
end
152170

153171
context 'when required parameters are missing' do

0 commit comments

Comments
 (0)