diff --git a/VERSION b/VERSION index 813b83b..c412a4e 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -4.13.0 +4.14.0 diff --git a/lib/buildkite/pipelines/command.rb b/lib/buildkite/pipelines/command.rb index 291d615..c8758a8 100644 --- a/lib/buildkite/pipelines/command.rb +++ b/lib/buildkite/pipelines/command.rb @@ -90,14 +90,24 @@ def run(exception: false) def to_a command = [BIN_PATH, @command, @subcommand] - command.concat(@options.to_a.flatten) - command.concat(@args) + # The `artifact` command has a different order of options and arguments: + # `buildkite-agent artifact upload [options] `, + # `buildkite-agent artifact download [options] `, + # `buildkite-agent artifact search [options] `, + # so we need to handle it separately. + if @command == 'artifact' + command.concat(@options.to_a.flatten) + command.concat(@args) + else + command.concat(@args) + command.concat(@options.to_a.flatten) + end end def extract_options(args) - return {} unless args.first.is_a?(Hash) + return {} unless args.last.is_a?(Hash) - args.shift.tap do |options| + args.pop.tap do |options| options.transform_keys! do |key| "--#{key.to_s.tr('_', '-')}" end diff --git a/spec/buildkite/pipelines/command_spec.rb b/spec/buildkite/pipelines/command_spec.rb index da81a7d..6d7e95f 100644 --- a/spec/buildkite/pipelines/command_spec.rb +++ b/spec/buildkite/pipelines/command_spec.rb @@ -72,7 +72,7 @@ let(:subcommand) { :upload } let(:options) { { foo_key: :foo_value, bar_key: :bar_value } } let(:args) { [Pathname.new('/path/to/foo'), Pathname.new('/path/to/bar')] } - let(:instance) { described_class.new(command, subcommand, options, *args) } + let(:instance) { described_class.new(command, subcommand, *args, options) } let(:mock_status) { instance_double(Process::Status, success?: true) } before do @@ -84,12 +84,12 @@ Buildkite::Pipelines::Command::BIN_PATH, command.to_s, subcommand.to_s, + '/path/to/foo', + '/path/to/bar', '--foo-key', 'foo_value', '--bar-key', 'bar_value', - '/path/to/foo', - '/path/to/bar' ) instance.run