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.

Variable replacement not working in 'jobs' the same as 'deployment' jobs.

See original GitHub issue

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: Docker@2

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

Environment

  • Server - Azure Pipelines or TFS on-premises? Azure Pipelines

  • Agent - Hosted or Private: Microsoft Hosted Agent

Issue Description

I have a simple task like this:

    - task: Docker@2
      displayName: Login to Docker Hub
      inputs:
        command: login
        containerRegistry: '$(dockerRegistry)'

If I define variable dockerRegistry within the pipeline file (inside variables block) then it works fine. However, if I import it from Pipeline Library like this:

variables:
  - group: 'Release'

then it does not work, the error message was "There was a resource authorization issue: “The pipeline is not valid. Job Build_and_Publish: Step Docker1 input containerRegistry references service connection $(dockerRegistry) 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.

I tried some simple echo and confirmed that echo $(containerRegistry) (and other variables in the same libary) works (i.e. the printed value is correct).

Task logs

[Enable debug logging and please provide the zip file containing all the logs for a speedy resolution]

Troubleshooting

Checkout how to troubleshoot failures and collect debug logs: https://docs.microsoft.com/en-us/vsts/build-release/actions/troubleshooting

Error logs

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

Issue Analytics

  • State:open
  • Created 3 years ago
  • Reactions:5
  • Comments:28 (5 by maintainers)

github_iconTop GitHub Comments

4reactions
alexandrebunncommented, Jun 28, 2022

We had the same issue. And we solved using the workaround moving the variable group to the top level with a conditional as suggested by @Zachery2008

3reactions
Zachery2008commented, Aug 26, 2020

I found a solution. You can save the acr connection as a variable in a variable group. And if you want to choose different variable groups depending on some conditions, you can do it at the top level. So the containerRegistry will treat it correctly. For example,

trigger:
- master

variables:
  # Agent VM image name
  - name: vmImageName
    value: ubuntu-latest
  - name: imageRepository
    value: xxx
  - name: dockerfilePath
    value: xxx
  - name: buildContextPath
    value: xxx
  - ${{ if eq(variables['Build.SourceBranch'], 'refs/heads/master') }}:
    - group: abc123
  - ${{ if eq(variables['Build.SourceBranch'], 'refs/heads/prod') }}:
    - group: xyz456

Read more comments on GitHub >

github_iconTop Results From Across the Web

Azure Pipelines - variable name not replaced in deployment job
I am trying to setup a multi-stage pipeline to run on a private agent. I believe top-level variables aren't getting replaced in subsequent...
Read more >
Retrieving an output variable from a deployment job
I'm trying to access an output variable from a deployment job in another deployment job. Both of these deployment jobs are in the...
Read more >
Define variables - Azure Pipelines | Microsoft Learn
When you define the same variable in multiple places with the ... Macro variables are not expanded when used to display a job...
Read more >
Create, run, and manage Databricks Jobs
If one or more tasks in a job with multiple tasks are not successful, you can re-run the subset of unsuccessful tasks. See...
Read more >
Variables - BMC Software
Named Pool: Enables any job in the same Named Pool that you define to reference the variable in any subsequent jobs in the...
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