从 Azure Pipeline .yaml 干净退出?

ori*_*zil 5 yaml exit azure-pipelines azure-pipelines-yaml

有没有比让脚本抛出错误更好/更干净/更惯用的方法来退出基于 .yaml 的 Azure Pipeline?

例如,这可行,但感觉很笨拙:

- task: PowerShell@2
  displayName: "Exit"
  inputs:
    targetType: 'inline'
    script: |
      throw 'Exiting';
Run Code Online (Sandbox Code Playgroud)

jes*_*ing 5

- powershell: |
  write-host "##vso[task.complete result=Failed;]The reason you quit"
Run Code Online (Sandbox Code Playgroud)

会更整洁,但仍然会失败。

没有相当于跳过作业的其余部分的方法,除非您使用条件来根据变量值跳过所有未来的任务:

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'))
Run Code Online (Sandbox Code Playgroud)

您可以使用模板中的YAML 迭代插入将该条件应用于我认为的作业中的所有任务。我手头没有工作示例,但文档显示了如何注入 a 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 }}
Run Code Online (Sandbox Code Playgroud)

  • 不,它只是标志着“任务”成功。就这样继续工作,就好像什么事都没有一样。 (2认同)