【问题标题】:How to use stages from 1 ymal pipeline to 2 pipeline Azure Devops如何使用从 1 个 yaml 管道到 2 个管道 Azure Devops 的阶段
【发布时间】:2021-05-24 18:15:39
【问题描述】:

我正在开展一个有 2 条管道的项目。 1 个管道目前正在按预期工作,其中包含 8 个阶段。

现在我想为 2 个管道编写代码,我想利用 1 个管道中的几个阶段(大约 4 个阶段),因为代码和功能相似。

有什么方法可以在 Azure DevOps YAML 管道中实现这一点?

【问题讨论】:

    标签: azure-devops yaml azure-pipelines azure-pipelines-yaml


    【解决方案1】:

    当然,您可以将类似的阶段导出到template,然后您可以在其他管道中使用extends

    # File: azure-pipelines.yml
    trigger:
    - master
    
    extends:
      template: start.yml
      parameters:
        buildSteps:  
          - bash: echo Test #Passes
            displayName: succeed
          - bash: echo "Test"
            displayName: succeed
          - task: CmdLine@2
            displayName: Test 3 - Will Fail
            inputs:
              script: echo "Script Test"
    

    模板将是(例如):

    # File: start.yml
    parameters:
    - name: buildSteps # the name of the parameter is buildSteps
      type: stepList # data type is StepList
      default: [] # default value of buildSteps
    stages:
    - stage: secure_buildstage
      pool: Hosted VS2017
      jobs:
      - job: secure_buildjob
        steps:
        - script: echo This happens before code 
          displayName: 'Base: Pre-build'
        - script: echo Building
          displayName: 'Base: Build'
    
        - ${{ each step in parameters.buildSteps }}:
          - ${{ each pair in step }}:
              ${{ if ne(pair.value, 'CmdLine@2') }}:
                ${{ pair.key }}: ${{ pair.value }}       
              ${{ if eq(pair.value, 'CmdLine@2') }}: 
                '${{ pair.value }}': error         
    
        - script: echo This happens after code
          displayName: 'Base: Signing'
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2020-01-27
      • 2020-10-31
      • 2022-09-23
      • 1970-01-01
      • 2020-10-26
      • 1970-01-01
      • 2021-03-25
      • 1970-01-01
      相关资源
      最近更新 更多