我是 Azure DevOps 新手。我希望在管道流期间自动创建 DevOps 管道环境。因此,如果环境不存在,下面的第 5 行应该创建环境:
- deployment: Deploy
displayName: Deploy job
pool:
vmImage: $(vmImageName)
environment: 'production'
相反,我得到:
我错过了什么?
为了自动创建环境,我还可以使用 Terraform,但这次我找不到负责此操作的 terraform 资源配置。
最佳答案
我遇到了类似的问题,并发现文档列出了发生这种情况的一些可能原因:
Q: Why am I getting error "Job XXXX: Environment XXXX could not be found. The environment does not exist or has not been authorized for use"?
A: These are some of the possible reasons of the failure:
When you author a YAML pipeline and refer to an environment that does not exist in the YAML file, Azure Pipelines automatically creates the environment in some cases:
- You use the YAML pipeline creation wizard in the Azure Pipelines web experience and refer to an environment that hasn't been created yet.
- You update the YAML file using the Azure Pipelines web editor and save the pipeline after adding a reference to an environment that does not exist.
In the following flows, Azure Pipelines does not have information about the user creating the environment: you update the YAML file using another external code editor, add a reference to an environment that does not exist, and then cause a manual or continuous integration pipeline to be triggered. In this case, Azure Pipelines does not know about the user. Previously, we handled this case by adding all the project contributors to the administrator role of the environment. Any member of the project could then change these permissions and prevent others from accessing the environment.
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.
A user with stakeholder access level cannot create the environment as stakeholders do not access to repository.
在我们的例子中,问题在于使用运行时参数来创建环境。 您对环境名称“生产”进行了硬编码,因此您的问题可能与其他情况之一有关。
关于azure - 在 yaml 管道配置中声明时,不会在 Azure Devops 中自动创建环境,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/69570537/