0

I have an inline script as shown. The requirement is that there could be different variables that needs to be passed and those are secretive. In azure pipelines, we can use variable groups and encrypt them. The idea is used below. From the documentation(https://learn.microsoft.com/en-us/azure/devops/pipelines/tasks/reference/bash-v3?view=azure-pipelines), arguments can be passed only if we write a shell script file, and execute the file through the task mentioned below.

However, the shell script file fails at the set -eufo pipefail command and it throws the following error:

/home/vsts/work/1/s/script.sh: line 2: set: pipefail
: invalid option name
##[error]Bash exited with code '2'.

Hence, there is an inline script as below:

variables:
- group: ScheduledUpdate

steps:
- task: Bash@3
  inputs:
    targetType: 'inline'
    arguments: '$(SOURCE_URL)'
    script: |
      #!usr/bin/sh
      set -eufo pipefail
      echo "Argument 1 is $1"
      echo "done"

However, there is a failure with respect to passing arguments. I get the following error:

/home/pkapikad/myagent/_work/_temp/7dfddc0a-4a40-4235-9752-c1c0e136372c.sh: line 3: $1: unbound variable
##[error]Bash exited with code '1'.
Finishing: Bash

Why is this caused? How can be pass arguments to a inline script inside bash task in azure devops?

RCB
  • 479
  • 1
  • 9
  • Only one question per question, please. Apparently you are not assigning a value for `$1` in your call so the `set -u` complains, because you asked it to. I guess the YAML is incorrectly indented ...? – tripleee Jan 11 '23 at 08:43
  • I am passing the URL info in the arguments. – RCB Jan 11 '23 at 08:47
  • https://learn.microsoft.com/en-us/azure/devops/pipelines/tasks/reference/bash-v3?view=azure-pipelines suggests that it's only valid when the task is a `filePath` but maybe refactor your question to _only_ ask about that and we can reopen it for hopefully a better answer. – tripleee Jan 11 '23 at 08:48
  • Oh wait, I found a duplicate for that too. – tripleee Jan 11 '23 at 08:49
  • https://stackoverflow.com/questions/71244892/how-to-pass-parameters-from-azure-pipeline-to-shell-script seems to suggest an alternative. – tripleee Jan 11 '23 at 08:52
  • I reopened.. The scriptarguments is for powershell tasks, not bash – RCB Jan 11 '23 at 08:58

0 Answers0