question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Stage-scoped Variables Not Respected for Azure CLI Task

See original GitHub issue

Note

Issues in this repo are for tracking bugs, feature requests and questions for the tasks in this repo

For a list:
https://github.com/Microsoft/azure-pipelines-tasks/tree/master/Tasks

If you have an issue or request for the Azure Pipelines service, use developer community instead:

https://developercommunity.visualstudio.com/spaces/21/index.html )

Required Information

Entering this information will route you directly to the right team and expedite traction.

Question, Bug, or Feature?
Type: Bug Enter Task Name: AzureCLI@2

list here (V# not needed):
https://github.com/Microsoft/azure-pipelines-tasks/tree/master/Tasks

Environment

  • Server - Azure Pipelines

    • If using Azure Pipelines, provide the account name, team project name, build definition name/build number:
  • Agent - Hosted

    • If using Hosted agent, provide agent queue name: Azure Pipelines

Issue Description

It doesn’t look like stage-scoped variables are respected when running the Azure CLI task. Is there anything on the roadmap for getting variables defined at the stage/job level supported? I’m trying to make our pipeline more dynamic by passing in variable templates for each environnment. Here is a generic overview of what I’m trying to do:

vars.yml

variables:
  serviceConnectionName: <service connection name>

cli task in template.yml

    - task: AzureCLI@2
      displayName: Disable Storage Account Firewall
      inputs:
        azureSubscription: $(serviceConnectionName)
        scriptType: 'bash'
        scriptLocation: 'inlineScript'
        inlineScript: |
          # Temporarily disable storage account firewall for Terraform access
          az storage account update -g $(appStorageAccountResourceGroupName) -n $(appStorageAccountName) --default-action=allow

And finally the main pipeline.yml, which references vars.yml in the stage definition:

stages:
- stage:
  displayName: Terraform Plan
  variables:
    - template: vars.yml
  jobs:
  - template: templates/template.yml

I would expect this to work, but instead the variable isn’t picked up by the pipeline at all, so the value remains as the literal string “serviceConnectionName.” This is the error in the Azure DevOps UI when running the pipeline:

There was a resource authorization issue: “The pipeline is not valid. Job TFPlan: Step AzureCLI1 input connectedServiceNameARM references service connection $(serviceConnectionName) which could not be found. The service connection does not exist or has not been authorized for use. For authorization details, refer to https://aka.ms/yamlauthz.,Job TFPlan: Step TerraformTaskV11 input backendServiceArm references service connection $(serviceConnectionName) which could not be found. The service connection does not exist or has not been authorized for use. For authorization details, refer to https://aka.ms/yamlauthz.

If I move the variable template files to the top of the pipeline.yml, and thus making them global variables, it works fine:

variables:
  - template: vars.yml
stages:
- stage:
  displayName: Terraform Plan
  jobs:
  - template: templates/template.yml

It might also be worth mentioning @chshrikh replied to another user on an issue with the AzFileCopy task and said that stage-scoped variables were not supported at the moment. Is this something that is common across all tasks or only a few?

Error logs

[Insert error from the logs here for a quick overview]

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:8 (3 by maintainers)

github_iconTop GitHub Comments

3reactions
rudolphjacksonmcommented, Apr 1, 2020

Raised a feature request on Dev Community for this, thanks again for your help @vtbassmatt . Feel free to correct me if I’ve gotten anything wrong here.

https://developercommunity.visualstudio.com/idea/973433/gather-stage-scoped-variables-when-preparing-stage.html

2reactions
vtbassmattcommented, Apr 1, 2020

Ah, thanks for clarifying. The problem is that for purposes of resolving resources, the system can only see variables at the pipeline level. In principle we could change this to also include stage variables (and it’s worth asking about that on Developer Community). Job-scoped variables will not work because we pause at the start of each stage – before any jobs have run – and collect up the resources to be authorized.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Azure CLI task failing due to missing input vaule
I have 2 Azure cli tasks as below. Our team executes this task based on the variable conditions. And sometimes we don't give...
Read more >
Saving output to variable not working in Azure-CLI DevOps task
The task.setvariable is a logging command and does not update the environment variables, but it does make the new variable available to ...
Read more >
AzureCLI@2 - Azure CLI v2 task - Microsoft Learn
Run Azure CLI commands against an Azure subscription in a PowerShell ... Syntax; Inputs; Output variables; Remarks; Examples; Requirements.
Read more >
Artifactory Azure DevOps Extension - JFrog Documentation
The new extension utilizes JFrog CLI V2. The old extension's Artifactory Generic Upload, Artifactory Generic Download and Artifactory Properties ...
Read more >
Azure PowerShell vs Azure CLI v2 - Quinn Gil
So it's not really IaC, it's ... Ia... Tasks. Anyway. In this I'm using the Azure CLI. ... Not all Create Commands respect...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found