經典模式
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類型管道的功能