'How to pass parameters from azure pipeline to shell script?

I'm trying to pass parameters to a shell script from an Azure pipeline. The shell script is being hit, but the parameters aren't coming over. Here is the pipeline task:

- task: AzureCLI@2
  inputs:
    azureSubscription: 'our-subscription'
    scriptType: 'bash'
    scriptLocation: 'scriptPath'
    scriptPath: 'Path/to/shellscript/cli.sh'
    arguments: 
    addSpnToEnvironment: 
      ${{ variables.appVersion }}
      ${{ variables.bNumber }}

Here is some of the cli.sh

appVersion=$1
buildNo=$2    
echo printing values:
echo appVersion= "$appVersion"
echo buildNo= "$buildNo"

Here is some of the log within the pipeline task

printing values: 
appVersion=  
buildNo=  
D:\a\1\s\path\to\shellscript\cli.sh: line 72: wget: command not found

Also note that the wget command is not being recognized either. What am I missing?



Solution 1:[1]

Usage of "addSpnToEnvironment" is to add service principal ID and key of the Azure endpoint you chose to the script's execution environment.

addSpnToEnvironment Access service principal details in script (Optional) Adds service principal ID and key of the Azure endpoint you chose to the script's execution environment. You can use these variables: $env:servicePrincipalId, $env:servicePrincipalKey and $env:tenantId in your script. This is honored only when the Azure endpoint has Service Principal authentication scheme Default value: false

And in your task you are trying to passing variables through this property which is syntactically not valid and here is what you can do to achieve the result you are looking for:

For quick test i passed your script as inline script instead of passing the script path.

variables:
- name: appVersion
  value: 1.0
- name: bNumber
  value: $(Build.BuildNumber)
steps:
- task: AzureCLI@2
  inputs:
    azureSubscription:'<subscription>'
    scriptType: 'bash'
    scriptLocation: 'inlineScript'
    inlineScript: |
      #!/bin/sh
      appVersion=$1
      buildNo=$2    
      echo printing values:
      echo appVersion= "$appVersion"
      echo buildNo= "$buildNo"
    arguments: '${{ variables.appVersion }} ${{ variables.bNumber }}'

Pipeline output:

printing values:
appVersion= 1.0
buildNo= 20220223.16
/usr/bin/az account clear
Finishing: AzureCLI

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1