azure - 是否可以在Azure DevOps中创建遵循幂等原则的PowerShell任务

标签 azure azure-devops azure-powershell

我正在使用 Azure DevOps 和 PowerShell 任务并创建具有多个管道的构建。我创建了一个版本,它将按照任务序列在 Azure 中创建资源,并使用顺序管道,例如,任务 1 创建资源组,任务 2 创建 Vnet 和子网,任务 3 创建存储,任务 4 创建存储虚拟机等等。我用 Terraform 做过类似的事情。但是在 AzureDevOps 中,当我尝试多次执行相同的构建时,我遇到了一个问题,它抛出资源已存在且管道显示运行失败的错误,我不希望管道运行并且不执行类似的操作幂等操作。我们如何在 Azure DevOps 中实现这一目标?

幂等操作可以重复任意次数,结果将与只执行一次相同。在算术中,数字加零是幂等的。

最佳答案

对于您的问题,我了解您希望为要执行的每个操作创建任务。任务将按顺序进行

您可以引用 Azure Yaml Schema 了解更多详细信息 https://learn.microsoft.com/en-us/azure/devops/pipelines/tasks/deploy/azure-powershell?view=azure-devops#yaml-snippet

steps:
  - task: AzurePowerShell@5
    name: Create Resource Group Name
    inputs:
      azureSubscription: $(serviceConnection)
      Inline: |
        $rgO = Get-AzResourceGroup -name ${{ parameters.ResourceGroupname }} -location ${{ parameters.location }}
        if(!$$rgO)
        {
          New-AzResourceGroup -name ${{ parameters.ResourceGroupname }} -location ${{ parameters.location }}
        }

关于azure - 是否可以在Azure DevOps中创建遵循幂等原则的PowerShell任务,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/63860393/

相关文章:

azure - 为什么我的 Azure Devops Pipeline 无法还原包?

node.js - 集成 LUIS 和 QnA 服务时 QnA 服务没有响应

azure - Azure Devops 托管代理的 ARM64 标签

powershell - 如何使用 Azure Powershell 模块将属性添加到 Azure 表存储行

时间:2019-03-17 标签:c#AzureFunctions分离html和css

Azure 发布管道 - Azure Key Vault 任务 VS 变量组

azure-devops - Markdown 文件中的 HTML 不会被渲染

Azure Devops - 如何从发布管道选项内的下拉列表中添加额外的部署类型

azure - “Find-AzureRmResource”未被识别为 cmdlet 的名称

azure - Connect-AzureAD -确认抛出 AADSTS900144 : The request body must contain the following parameter: 'code' . 错误