Why does Azure Pipelines say "The environment does not exist or has not been authorized for use"?
Asked Answered
C

3

11

In Azure Pipelines YAML, you can specify an environment for a job to run in.

  jobs:
    - deployment: Deploy
      displayName: Deploy
      environment: $(environment)

Passing a new value to the pipeline should automatically create the Environment in DevOps.

Automatically created environment

However, I have recently gotten this error when attempting to deploy to a new environment:

Job Deploy: Environment [environment-name] could not be found. The environment does not exist or has not been authorized for use.

After I created the environment manually, the pipeline deployed successfully.

Is there any configuration or something I'm missing that would allow the environment to be created automatically?

Cavein answered 12/10, 2021 at 20:13 Comment(0)
E
4

I have same issue and according to documentation it's not possible to create Environment this way.

If you are using runtime parameters for creating the environment, it will fail as these parameters are expanded at run time. Environment creation happens at compile time, so we have to use variables to create the environment.

For more info please check here.

Escallop answered 28/10, 2021 at 12:24 Comment(1)
According to the link, this behavior changed recently... "Previously, we handled this case by adding all the project contributors to the administrator role of the environment..."Cavein
T
7

Why does Azure Pipelines say "The environment does not exist or has not been authorized for use"?

First, you need to make sure you are Creator in the Security of environment:

enter image description here

Second, make sure change/create the environment name from yaml editor, not from repo.

If above not help you, may I know what is your role in the project, Project Reader?

Thermoluminescence answered 13/10, 2021 at 7:32 Comment(4)
Thanks. Yes, I'm listed as Creator in Security. The environment name changed based on the value of the variable $(environment) in the yaml, because a new value was assigned the variable that was never used as an Environment. Is that what you mean?Cavein
To answer your last question, I am a Contributor to the project. However, I'm not triggering the pipeline directly - it's a CI/CD pipeline that is triggered by changes to the repo.Cavein
I also ran in to the issue the OP is talking about. We are using templating in our pipelines. Originally, the role I was assigned to was "Read Only." After updating the role to "User" or "Administrator" it worked.Sharp
I had a similar issue. Going into the individual environments and setting the contributors to "User" solved the issue.Veliavelick
E
4

I have same issue and according to documentation it's not possible to create Environment this way.

If you are using runtime parameters for creating the environment, it will fail as these parameters are expanded at run time. Environment creation happens at compile time, so we have to use variables to create the environment.

For more info please check here.

Escallop answered 28/10, 2021 at 12:24 Comment(1)
According to the link, this behavior changed recently... "Previously, we handled this case by adding all the project contributors to the administrator role of the environment..."Cavein
E
0

May be the vm on which you are trying to deploy does not exist in the environment. try using correct env.

Emeldaemelen answered 9/7 at 18:2 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.