azure - 在 yaml 管道配置中声明时,不会在 Azure Devops 中自动创建环境

标签 azure azure-devops terraform

我是 Azure DevOps 新手。我希望在管道流期间自动创建 DevOps 管道环境。因此,如果环境不存在,下面的第 5 行应该创建环境:

  - deployment: Deploy
    displayName: Deploy job
    pool:
      vmImage: $(vmImageName)
    environment: 'production'

相反,我得到:

Error I'm getting

我错过了什么?

为了自动创建环境,我还可以使用 Terraform,但这次我找不到负责此操作的 terraform 资源配置。

最佳答案

我遇到了类似的问题,并发现文档列出了发生这种情况的一些可能原因:

引自learn.microsoft.com :

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/

相关文章:

在附加时刷新门户/存储资源管理器时,Azure Blob 存储附加 blob 409/修改错误

azure - Sharepoint API Headless 获取访问 token

azure - 下载 Excel 文件并使用 azure 函数读取内容

azure-devops - 构建管道可视化设计器中某个任务的 YAML 中的注释的目的是什么?

需要在 Terraform 服务主体的整个订阅中授予 Azure RBAC 角色 'ConfigureFactoryRepo' 才能启动数据工厂

azure - 使用 Azure BlockBlob 进行日志记录(使用多个写入器方案写入文本文件)

c# - 使用 Visual Studio Team Services 进行自动化用户界面测试

azure - Azure DevOps 管道可以按特定顺序运行吗?

azure - Terraform - 如何获取 azurerm Key Vault 访问策略的应用服务对象 ID?

image - 使用 terraform 从自定义镜像创建 azure vm 错误