针对特定环境的Azure DevOps管道

发布于 2025-02-11 22:22:46 字数 315 浏览 2 评论 0原文

我有两个ADO管道是CI和CD,当CI完成CD自动触发时,它们正在运行。

我的要求是我在CI和CD工作中有3个环境,例如Dev STG和ITG CI完成后,我想根据环境选择部署CD作业。

可以说,当我使用Dev stack触发CI作业时,CI完成了CI完成,CD应触发DEV堆栈。 类似地,对于完成CD -ITG堆栈后选择的CI -ITG应该自动完成。

是否有任何方法可以将这两个管道链接起来,以根据环境选择触发。

注意:默认情况下,DEV堆栈在CI和CD之间正常工作,但是当我在CI作业中选择ITG并在CI-ITG完成后,在CD作业开发DEV不运行ITG中。

I have two ADO pipelines one is CI and CD and they are running when CI is completed CD automatically getting triggered without any issues.

My requirement is I have 3 environments in CI and CD jobs like dev stg and itg
I want to deploy my CD job based on environments selections automatically when CI completed.

lets say when I trigger CI job with Dev stack and once CI completed with Dev stack , CD should get triggered dev stack.
similarly for CI -itg selected once done CD- itg stack should be done automatically.

is there any way to link this two pipelines to get triggered based on environments selections.

Note : by default dev stack is working fine between CI and CD, but when I select itg in CI job and as soon as CI-itg completed , in CD job dev running not itg.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

歌入人心 2025-02-18 22:22:46

根据您的要求,您需要根据CI管道阶段运行触发CD管道阶段。

恐怕没有盒子外的方法可以达到这一要求。

对于解决方法,我建议您可以自然定义发行管道中的变量,并且可以通过REST API修改CI管道中的释放管道变量:“ noreferrer”>“ deactions-update ”。

请参阅以下步骤:

步骤1:定义Release Pipeline变量。

步骤2:在每个阶段添加一个步骤以在CI管道中运行PowerShell脚本。当管道阶段运行时,它将在重酶管道中修改值。

例如:

stages:
  - stage: Dev
    jobs:
      - job: A 
        steps:
          - task: PowerShell@2
            inputs:
              targetType: 'inline'
              script: |
                $url = "https://vsrm.dev.azure.com/{organization}/{project}/_apis/release/definitions/{definitionId}?api-version=5.1"
                
                Write-Host "URL: $url"
                $pipeline = Invoke-RestMethod -Uri $url -Method Get -Headers @{
                    Authorization = "Bearer $env:SYSTEM_ACCESSTOKEN"
                }
                Write-Host "Pipeline = $($pipeline | ConvertTo-Json -Depth 100)"
                
                # Update an existing variable named TestVar to its new value 2
                $pipeline.variables.Dev.value = "Yes"
                
                ####****************** update the modified object **************************
                $json = @($pipeline) | ConvertTo-Json -Depth 99
                
                $updatedef = Invoke-RestMethod -Uri $url -Method Put -Body $json -ContentType "application/json" -Headers @{Authorization = "Bearer $env:SYSTEM_ACCESSTOKEN"}
                
                write-host "==========================================================" 
                Write-host "The value of Varialbe 'Dev' is updated to" $updatedef.variables.Dev.value


  - stage: Stg
    jobs:
      - job: B 
        steps:
          - task: PowerShell@2
            inputs:
              targetType: 'inline'
              script: |
                $url = "https://vsrm.dev.azure.com/{organization}/{project}/_apis/release/definitions/{definitionId}?api-version=5.1"
                
                Write-Host "URL: $url"
                $pipeline = Invoke-RestMethod -Uri $url -Method Get -Headers @{
                    Authorization = "Bearer $env:SYSTEM_ACCESSTOKEN"
                }
                Write-Host "Pipeline = $($pipeline | ConvertTo-Json -Depth 100)"
                
                # Update an existing variable named TestVar to its new value 2
                $pipeline.variables.stg .value = "Yes"
                
                ####****************** update the modified object **************************
                $json = @($pipeline) | ConvertTo-Json -Depth 99
                
                $updatedef = Invoke-RestMethod -Uri $url -Method Put -Body $json -ContentType "application/json" -Headers @{Authorization = "Bearer $env:SYSTEM_ACCESSTOKEN"}
                
                write-host "==========================================================" 
                Write-host "The value of Varialbe 'stg ' is updated to" $updatedef.variables.stg .value

step3:在Release Pipeline阶段中,您可以设置条件:eq(变量['dev'],'yes')

例如:

Based on your requiremnt, you need to trigger the CD Pipeline stage based on the CI Pipeline stage running.

I am afraid that there is no out-of-box method can achieve this requirement.

For a workaround, I suggest that you can manaully define the variable in Release Pipeline and you can modify the release pipeline variable in CI pipeline via Rest API:Definitions - Update .

Refer to the following steps:

Step1: Define Release Pipeline variable.

enter image description here

Step2: Add a step to run PowerShell script in CI pipeline to each stage. When the Pipeline stage run, it will modify the value in Relase Pipeline.

For example:

stages:
  - stage: Dev
    jobs:
      - job: A 
        steps:
          - task: PowerShell@2
            inputs:
              targetType: 'inline'
              script: |
                $url = "https://vsrm.dev.azure.com/{organization}/{project}/_apis/release/definitions/{definitionId}?api-version=5.1"
                
                Write-Host "URL: $url"
                $pipeline = Invoke-RestMethod -Uri $url -Method Get -Headers @{
                    Authorization = "Bearer $env:SYSTEM_ACCESSTOKEN"
                }
                Write-Host "Pipeline = $($pipeline | ConvertTo-Json -Depth 100)"
                
                # Update an existing variable named TestVar to its new value 2
                $pipeline.variables.Dev.value = "Yes"
                
                ####****************** update the modified object **************************
                $json = @($pipeline) | ConvertTo-Json -Depth 99
                
                $updatedef = Invoke-RestMethod -Uri $url -Method Put -Body $json -ContentType "application/json" -Headers @{Authorization = "Bearer $env:SYSTEM_ACCESSTOKEN"}
                
                write-host "==========================================================" 
                Write-host "The value of Varialbe 'Dev' is updated to" $updatedef.variables.Dev.value


  - stage: Stg
    jobs:
      - job: B 
        steps:
          - task: PowerShell@2
            inputs:
              targetType: 'inline'
              script: |
                $url = "https://vsrm.dev.azure.com/{organization}/{project}/_apis/release/definitions/{definitionId}?api-version=5.1"
                
                Write-Host "URL: $url"
                $pipeline = Invoke-RestMethod -Uri $url -Method Get -Headers @{
                    Authorization = "Bearer $env:SYSTEM_ACCESSTOKEN"
                }
                Write-Host "Pipeline = $($pipeline | ConvertTo-Json -Depth 100)"
                
                # Update an existing variable named TestVar to its new value 2
                $pipeline.variables.stg .value = "Yes"
                
                ####****************** update the modified object **************************
                $json = @($pipeline) | ConvertTo-Json -Depth 99
                
                $updatedef = Invoke-RestMethod -Uri $url -Method Put -Body $json -ContentType "application/json" -Headers @{Authorization = "Bearer $env:SYSTEM_ACCESSTOKEN"}
                
                write-host "==========================================================" 
                Write-host "The value of Varialbe 'stg ' is updated to" $updatedef.variables.stg .value

Step3: In Release Pipeline stage, you can set the condition:eq(variables['dev'], 'Yes')

For example:

enter image description here

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文