Azure DevOps YAML:条件模板调用

问题描述 投票:0回答:1

我想检查 Fetch_Commits 是否成功,以便在

microservice-calls.yaml
文件中运行作业。 我不想使用阶段,因为没有用于分隔作业的语义。

是否有类似的语法

- ${{ if succeeded('Fetch_Commits') }}:
     - template: templates/microservices-calls.yaml

YAML 文件:

trigger:
- trigger-branch

jobs:
    - job: Fetch_Commits
      displayName: Checkout
      pool:
       name: MyPool
      steps:
      - checkout: self
        fetchDepth: 2
    - ${{ if succeeded('Fetch_Commits') }}:
      - template: templates/microservices-calls.yaml
azure-devops continuous-integration azure-pipelines azure-pipelines-release-pipeline azure-pipelines-yaml
1个回答
0
投票

yaml 中的

Fetch_Commits
是作业名称。您可以使用
dependsOn
condition
属性根据另一个作业的成功情况来控制作业执行。

修改后的YAML文件:

trigger:
- trigger-branch

jobs:
  - job: Fetch_Commits
    displayName: Checkout
    pool:
      name: MyPool
    steps:
    - checkout: self
      fetchDepth: 2

  - job: Run_Microservices
    displayName: Run Microservices
    dependsOn: Fetch_Commits
    condition: succeeded('Fetch_Commits')
    steps:
    - template: templates/microservices-calls.yaml

仅当

Run_Microservices
作业成功时,
Fetch_Commits
作业才会运行。

您还可以在同一作业中进行结帐步骤和微服务调用。在以下示例中,

Fetch_Commits
步骤和
microservices calls
是同一作业的一部分。如果
Fetch_Commits
步骤失败,作业将停止,并且
microservices calls
将不会运行。

trigger:
- trigger-branch

jobs:
  - job: Job1
    displayName: Checkout and Run Microservices
    pool:
      name: MyPool
    steps:
    - checkout: self
      fetchDepth: 2
      displayName: Fetch_Commits
    - template: templates/microservices-calls.yaml

在这种情况下,不需要

${{ if succeeded('Fetch_Commits') }}:

© www.soinside.com 2019 - 2024. All rights reserved.