简体   繁体   English

“Run this job” based on value in angular.json in Azure Release Pipeline

[英]“Run this job” based on value in angular.json in Azure Release Pipeline

Is there any way to stop the Azure CI/CD pipeline bases on the values in angular.json有没有办法根据 angular.json 中的值停止 Azure CI/CD 管道

在此处输入图像描述

I need to run the pipeline only when "defaultProject" contains 'pos-ac-pos' which is in angular.json file.仅当“defaultProject”包含 angular.json 文件中的“pos-ac-pos”时,我才需要运行管道。

You can add a script task to check the value of defaultProject .您可以添加一个脚本任务来检查defaultProject的值。 If the value is not pos-ac-pos , you can stop the pipeline manually.如果该值不是pos-ac-pos ,您可以手动停止管道。 For below example in powershell script:对于 powershell 脚本中的以下示例:

steps:
- powershell: |
   $angular = (Get-Content "$(system.defaultworkingdirectory)/angular.json" -Raw) | ConvertFrom-Json
   
   if ($angular.defaultProject -ne "pos-ac-pos"){
   
     exit 1
   }
  displayName: 'PowerShell Script'

If you add a powershell task to run above script in your pipeline.如果您添加 powershell 任务以在您的管道中运行上面的脚本。 When the defaultProject isnot pos-ac-pos.当 defaultProject 不是 pos-ac-pos 时。 The task will fail and stop the pipeline.该任务将失败并停止管道。

You can also create new pipeline as a triggering pipeline with above script task to check the value of defaultProject .您还可以使用上述脚本任务创建新管道作为触发管道,以检查defaultProject的值。 And trigger your main pipeline by using Trigger Build task Or using rest api , if the script task succeed.并通过使用Trigger Build 任务或使用rest api触发您的主管道,如果脚本任务成功。 See below example:请参阅以下示例:

steps:
    - powershell: |
       $angular = (Get-Content "$(system.defaultworkingdirectory)/angular.json" -Raw) | ConvertFrom-Json
       
       if ($angular.defaultProject -ne "pos-ac-pos"){
       
         exit 1
       }
      displayName: 'PowerShell Script'
   
   - task: benjhuser.tfs-extensions-build-tasks.trigger-build-task.TriggerBuild@3
     displayName: 'Trigger a new build of 12'
     inputs:
       buildDefinition: 12

Note: You might need to disable the CI trigger of the main pipeline.注意:您可能需要禁用主管道的 CI 触发器。 For it will be triggered by the new triggering pipeline.因为它将由新的触发管道触发。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM