0
votes

I am having issues passing parameters defined in an Azure Pipeline YAML to AZ Cli located in a bash script. I found the following solution on Stackoverflow but it doesn't seem to work: Pass parameter to Azure CLI Task in DevOps

Here is my YAML file:

# Starter pipeline
# Start with a minimal pipeline that you can customize to build and deploy your code.
# Add steps that build, run tests, deploy, and more:
# https://aka.ms/yaml

trigger:
- master

pool:
  vmImage: 'ubuntu-latest'

steps:
- task: AzureCLI@2
  displayName: Azure CLI
  inputs:
    azureSubscription: templateresourceconnection
    scriptType: bash
    scriptPath: ./deployment.sh
    arguments:
      -resourceGrp 'TEST-RG'
      -location 'westeurope'

I would expect to be able to access the arguments in my deployment.sh, which fails:


#!/bin/bash

# Create Resource Group
az group create -n $(resourceGrp) -l $(location)

If I don't pass any arguments and hardcode the values in deployment.sh it all works fine. Any ideas what could cause this issue? I also tried with UPPERCASE and just without brackets.

I get the following error message

Azure Pipelines Error Message

Do you have any idea what else I could try to make it work. Seems like the documentation doesn't contain any example for az cli. Just how to define parameters but not how to pass them afterwards.

Thank you.

1
Hi @user6196039. Is there any update about this ticket? Feel free to let me know if the answer could give you some help. Just a remind of this.Kevin Lu-MSFT

1 Answers

0
votes

Do you have any idea what else I could try to make it work

You could try to use the Environment variable. Environment variables can be accessed by bash script files.

First of all, you need to define pipeline variable instead of task argument.

variables:
- name: one
  value: initialValue 

Here is my example: Used in Linux system.

az group create -n $RESOURCEGRP -l $LOCATION

Note: All characters in environment variables need to be capitalized.

e.g.: resourceGrp -> $RESOURCEGRP

Yaml sample:

variables:
- name: resourceGrp
  value: TEST-RG
- name: location
  value: westeurope

pool:
  vmImage: 'ubuntu-latest'

steps:

- task: AzureCLI@2
  displayName: 'Azure CLI deploy.sh'
  inputs:
    azureSubscription: kevin0209
    scriptType: bash
    scriptPath: ./deployment.sh