テンプレートを使用してパイプラインを拡張します。
extends:
template: string # The template referenced by the pipeline to extend.
parameters: # Parameters used in the extend.
特性
template
文字列。
拡張するパイプラインによって参照されるテンプレート。
テンプレート パラメーターを parameters
します。
拡張で使用されるパラメーター。
例示
テンプレートとそのパラメーターは、パイプラインを実行する前に定数に変換されます。
テンプレート パラメーターは、入力パラメーターにタイプ セーフを提供します。
この例では、テンプレート start.yml
によってパラメーター buildSteps
が定義され、 azure-pipelines.yml
で使用されます。 スクリプト ステップで buildStep が渡された場合、それは拒否され、パイプラインのビルドは失敗します。
# 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:
vmImage: windows-latest
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') }}:
# Step is rejected by raising a YAML syntax error: Unexpected value 'CmdLine@2'
'${{ pair.value }}': error
- script: echo This happens after code
displayName: 'Base: Signing'
# File: azure-pipelines.yml
trigger:
- main
extends:
template: start.yml
parameters:
buildSteps:
- bash: echo Test #Passes
displayName: succeed
- bash: echo "Test"
displayName: succeed
# Step is rejected by raising a YAML syntax error: Unexpected value 'CmdLine@2'
- task: CmdLine@2
inputs:
script: echo "Script Test"
# Step is rejected by raising a YAML syntax error: Unexpected value 'CmdLine@2'
- script: echo "Script Test"
こちらもご覧ください
- 使用 & テンプレートの種類
- テンプレートによるセキュリティ