ADS 流水线模板

经典模式

Azure Devops Server 2019 , Team Foundation Server 2018
另存为模版即可
可以在模版上管理权限,比如不能修改模版
但是继承模版后依然可以随意调整

Yaml文件模式

使用引用其他git库的yaml文件,可以编写通用的模版,并可以实现yaml模版被引用后,模版中的步骤不能跳过 也不能被篡改。

Azure Devops Server 2019

新建模版库,创建yaml文件

# core-template.yml
# ASP.NET Core
# Build and test ASP.NET Core projects targeting .NET Core.
# Add steps that run tests, create a NuGet package, deploy, and more:
# https://docs.microsoft.com/azure/devops/pipelines/languages/dotnet-core

parameters:
- name: buildConfiguration
  type: string
  default: Release
  values: 
  - Release
  - Debug

- name: buildSteps # the name of the parameter is buildSteps
  type: stepList # data type is StepList
  default: [] # default value of buildSteps

#steps:
#- script: dotnet build --configuration ${{ parameters.buildConfiguration }}
#  displayName: 'dotnet build ${{ parameters.buildConfiguration }}'

stages:
- stage: secure_buildstage
  pool: Default
  jobs:
  - job: secure_buildjob
    steps:
    - script: echo This happens before code 
      displayName: 'Pre-build'

    - script: dotnet build --configuration ${{ parameters.buildConfiguration }}
      displayName: 'dotnet build ${{ parameters.buildConfiguration }}'

    - ${{ each step in parameters.buildSteps }}:
      - ${{ each pair in step }}:
          ${{ pair.key }}: ${{ pair.value }}       
       
    - script: echo This happens after code
      displayName: 'Complete'

引用模版的yaml
新建管道

选择yaml类型

# Repo: PipelineTemplateTest/PipelineTemplateTest
# File: azure-pipelines.yml

# 从其他的azure devops repos库中引用
resources:
  repositories:
    - repository: templates
      type: git
      name: YamlTemplate/YamlTemplate  # 项目名称 / 存储库名称

trigger: 
- master

pool: 
  name: 'Default' 

# 导入模版,并设置变量的值
extends:
  template: core-template.yml@templates # yaml文件的名称 @ 上面申明的模版库名称
  parameters:
      buildConfiguration: 'Debug'
      buildSteps:  
        - script: echo Test 
          displayName: test succeed
        - task: CmdLine@2
          displayName: Test 3 - Will Fail
          inputs:
            script: echo "Script Test"

流水线运行结果

Team Foundation Server 2018

不具备创建yaml类型管道的功能

参考资料
https://docs.microsoft.com/en-us/azure/devops/pipelines/process/templates?view=azure-devops#use-other-repositories

posted @ 2022-12-16 15:40  远方V3  阅读(66)  评论(0编辑  收藏  举报