避免在天蓝色管道中跨多个池重复执行步骤

时间:2018-09-25 22:50:10

标签: azure-pipelines

我有一个netstandard库,我想在多个平台(Windows和Linux)上进行构建和测试。

当前我必须这样做

jobs:
  - job: Linux
    pool:
      vmImage: ubuntu-16.04
    steps:
        # A number of steps here

  - job: Windows
    pool:
      vmImage: vs2017-win2016
    steps:
        # The exact same steps as the linux job

有什么方法可以避免在作业之间重复步骤?

1 个答案:

答案 0 :(得分:0)

恐怕如果您在天蓝色管道中跨越多个池,则必须为每个池分别设置步骤。

不过,您可以尝试使用模板。可以在一个文件中定义一个步骤,而在另一个文件中使用多个位置。

有关详细信息,请参见YAML schema reference - Step template

# File: steps/build.yml

steps:
- script: npm install
- script: npm test

跨多个池:

# File: azure-pipelines.yml

jobs:
- job: macOS
  pool:
    vmImage: 'macOS-10.13'
  steps:
  - template: steps/build.yml # Template reference

- job: Linux
  pool:
    vmImage: 'Ubuntu-16.04'
  steps:
  - template: steps/build.yml # Template reference

- job: Windows
  pool:
    vmImage: 'VS2017-Win2016'
  steps:
  - template: steps/build.yml # Template reference
  - script: sign              # Extra step on Windows only
相关问题