Peter
Peter

Reputation: 3857

Cannot authorize variable group in Azure Pipelines

I am constructing a multi-stage Azure Pipeline in Azure DevOps to build and release my product.

I want to use variable groups in this pipeline, so that I can substitute different configuration values for different deployment environments.

I am unable to authorize my variable groups to be used by the pipeline. When I manually run a build, I see a message on the summary page telling me the variable group is not authorized: Error message

The Azure DevOps documentation says this is to be expected:

When you make changes to the YAML file and add additional resources (assuming that these not authorized for use in all pipelines as explained above), then the build fails with a resource authorization error that is similar to the following: Could not find a {RESOURCE} with name {NAME}. The {RESOURCE} does not exist or has not been authorized for use.

In this case, on the Summary page, you will see an option to authorize the resources on the failed build. If you are a member of the User role for the resource, you can select this option. Once the resources are authorized, you can start a new build.

I am a member of the User role for the variable group, and I am seeing the message, but I am presented with no option to authorize. Is there something else I need to do? Or is there another way I can authorize a specific pipeline to use a variable group?

Upvotes: 14

Views: 25162

Answers (4)

DataBach
DataBach

Reputation: 1624

I encountered a similar issue where I needed to use variables from a template instead of a variable group. Initially, I made the mistake of writing:

variables:
- group: "/workbooks/apps/deployment/templates/variables/${{lower(parameters.targetEnv)}}.yml"

However, the correct syntax should be:

variables:
  - template: "/workbooks/apps/deployment/templates/variables/${{lower(parameters.targetEnv)}}.yml"

Just in case this helps, since we don't have the code from the OP. Variables from yml files are not part of groups and are not managed there. Maybe it is obvious but in a hurry one might miss that.

Upvotes: 0

devmo
devmo

Reputation: 91

I had this issue as well, but it was because when I created a variable group under Pipelines > Library, the name in Azure Portal did not match the name in my yml file.

Upvotes: 5

Frederic de smet
Frederic de smet

Reputation: 179

The provided solution proposed by @hey didn't work for me because i had to use deployment jobs. I've found a hacky way to resolve this error:

  1. Go to your pipeline
  2. Edit
  3. Click on the tree dots > Triggers
  4. Navigate to the variables tab
  5. Variable groups
  6. Add variable groups

Upvotes: 17

Hugh Lin
Hugh Lin

Reputation: 19381

Variable groups can only be accessed if they are imported at the "job" level.

Solution:

I have tested and tried to reproduce your issue. In order to solve it, you need to add the variable group under "job".

Explanation / Analysis:

This is how to reproduce and solve the issue:

First, I have tested with the below yaml script, by adding the variable group to the stage (literally at the same level as jobs):

stages:
- stage: build
  variables:
    - group: 789
  jobs:
  - job: run_build
    pool:
      vmImage: 'Ubuntu 16.04'
    steps:
    - script: echo Build

With this configuration, I was not able to use the variable group. I got the same issue as you:

enter image description here

I then moved the variable group into the job section of the yaml file:

stages:
- stage: build
  jobs:
  - job: run_build
    pool:
      vmImage: 'Ubuntu 16.04'
    steps:
    - script: echo Build
    variables:
    - group: 789

With the modified configuration, I was able to see and use the Authorize resources option in the error message:

enter image description here

Upvotes: 9

Related Questions