How do I supply Exec task args correctly?

Hello,

I am trying to convert the following shell command line to a task:

$ aws s3 sync --delete --exclude "*/tmp-*" srcPath destPath
tasks.create(name: taskName, type: Exec) {
          executable = 'aws'
          args = ['s3', 'sync', '--delete', '--exclude', '*/tmp-*', srcPath, destPath]
      }

The task runs, but exclude doesn’t work – it does work in bash.

At first I tried a too literal version of the bash line via

'--exclude', '"*/tmp-*"'

But even after removing the " the exclusion still doesn’t work…

Thanks in advance!

Wildcards (as used in ‘’/tmp-’’) are a bash feature. If you want to use bash features, you need to call the ‘bash’ executable, and tell it to run the ‘aws’ command.

There is no wildcard expansion done by bash – the bash command line argument is enclosed in " It’s the invoked executable (aws) that uses the --exclude argument.

Thanks for your reply!

There is no other reason I can think of.

The Exec task appears to be taking the absolute srcPath argument and making it relative. The relative path supplied to the executable (aws) causes the match pattern to miss.

How do I get Exec not to automagically relativize my srcPath?

Thanks!

Are you sure srcPath is an absolute path?

If you println srcPath inside the configuration block for your Exec task, is it absolute then?

I don’t see anything special in the Exec code that would know how to make paths relative in the arguments. It looks like it just calls toString on all of the arguments.