从 Azure Pipeline .yaml 清除退出?
Clean Exit from an Azure Pipeline .yaml?
是否有 better/cleaner/more 退出基于 .yaml 的 Azure Pipeline 的惯用方法而不是让脚本抛出错误?
例如,这可行但感觉笨拙:
- task: PowerShell@2
displayName: "Exit"
inputs:
targetType: 'inline'
script: |
throw 'Exiting';
- powershell: |
write-host "##vso[task.complete result=Failed;]The reason you quit"
会更整洁,但仍然会失败。
没有跳过剩余工作的等效方法,除非您使用条件来根据变量值跳过所有未来的任务:
variables:
skiprest: false
- powershell: |
write-host "##vso[task.setvariable variable=skiprest]true"
- powershell:
condition: and(succeeded(), eq(skiprest, 'false'))
- powershell:
condition: and(succeeded(), eq(skiprest, 'false'))
- powershell:
condition: and(succeeded(), eq(skiprest, 'false'))
- powershell:
condition: and(succeeded(), eq(skiprest, 'false'))
您可以使用模板中的 YAML iterative insertion 将该条件应用于我想的工作中的所有任务。我手边没有可用的示例,但文档显示了如何注入 dependsOn:
,我想这个技巧非常相似:
# job.yml
parameters:
- name: 'jobs'
type: jobList
default: []
jobs:
- job: SomeSpecialTool # Run your special tool in its own job first
steps:
- task: RunSpecialTool@1
- ${{ each job in parameters.jobs }}: # Then do each job
- ${{ each pair in job }}: # Insert all properties other than "dependsOn"
${{ if ne(pair.key, 'dependsOn') }}:
${{ pair.key }}: ${{ pair.value }}
dependsOn: # Inject dependency
- SomeSpecialTool
- ${{ if job.dependsOn }}:
- ${{ job.dependsOn }}
是否有 better/cleaner/more 退出基于 .yaml 的 Azure Pipeline 的惯用方法而不是让脚本抛出错误?
例如,这可行但感觉笨拙:
- task: PowerShell@2
displayName: "Exit"
inputs:
targetType: 'inline'
script: |
throw 'Exiting';
- powershell: |
write-host "##vso[task.complete result=Failed;]The reason you quit"
会更整洁,但仍然会失败。
没有跳过剩余工作的等效方法,除非您使用条件来根据变量值跳过所有未来的任务:
variables:
skiprest: false
- powershell: |
write-host "##vso[task.setvariable variable=skiprest]true"
- powershell:
condition: and(succeeded(), eq(skiprest, 'false'))
- powershell:
condition: and(succeeded(), eq(skiprest, 'false'))
- powershell:
condition: and(succeeded(), eq(skiprest, 'false'))
- powershell:
condition: and(succeeded(), eq(skiprest, 'false'))
您可以使用模板中的 YAML iterative insertion 将该条件应用于我想的工作中的所有任务。我手边没有可用的示例,但文档显示了如何注入 dependsOn:
,我想这个技巧非常相似:
# job.yml
parameters:
- name: 'jobs'
type: jobList
default: []
jobs:
- job: SomeSpecialTool # Run your special tool in its own job first
steps:
- task: RunSpecialTool@1
- ${{ each job in parameters.jobs }}: # Then do each job
- ${{ each pair in job }}: # Insert all properties other than "dependsOn"
${{ if ne(pair.key, 'dependsOn') }}:
${{ pair.key }}: ${{ pair.value }}
dependsOn: # Inject dependency
- SomeSpecialTool
- ${{ if job.dependsOn }}:
- ${{ job.dependsOn }}