Skip to content

Commit 55fc395

Browse files
authored
inheritance templates (#8)
* Inheritance template that rejects a task * Inheritance template that removes or a replace a task
1 parent af52089 commit 55fc395

File tree

4 files changed

+105
-0
lines changed

4 files changed

+105
-0
lines changed
+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
trigger:
2+
branches:
3+
include:
4+
- '*'
5+
6+
extends:
7+
template: template.yml
8+
parameters:
9+
buildSteps:
10+
- bash: echo Test #Passes
11+
displayName: Bash A
12+
- bash: echo "Test"
13+
displayName: Bash B
14+
- task: CmdLine@2
15+
displayName: Test 3 - Will Fail
16+
inputs:
17+
script: echo "Script Test"
18+
- script: echo Test 4 - Will Fail

templates/reject-task/template.yml

+37
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
# File: start.yml
2+
parameters:
3+
- name: buildSteps # the name of the parameter is buildSteps
4+
type: stepList # data type is StepList
5+
default: [] # default value of buildSteps
6+
stages:
7+
- stage: secure_buildstage
8+
pool:
9+
vmImage: windows-latest
10+
jobs:
11+
- job: secure_buildjob
12+
steps:
13+
- script: echo This happens before code
14+
displayName: 'Base: Pre-build'
15+
- script: echo Building
16+
displayName: 'Base: Build'
17+
18+
- ${{ each step in parameters.buildSteps }}:
19+
- ${{ each pair in step }}:
20+
# The
21+
${{ if startsWith(pair.value, 'Bash') }}:
22+
# Will throw syntax error: Unexpected value 'Not allowed to use Bash'
23+
"Not allowed to use Bash": error
24+
${{ elseif startsWith(pair.value, 'CmdLine') }}:
25+
# Will throw syntax error: Unexpected value 'Not allowed to use BatchScript'
26+
"Not allowed to use BatchScript": error
27+
${{ elseif startsWith(pair.value, 'PowerShell') }}:
28+
# Will throw syntax error: Unexpected value 'Not allowed to use PowerShell'
29+
"Not allowed to use PowerShell": error
30+
${{ elseif startsWith(pair.value, 'ShellScript') }}:
31+
# Will throw syntax error: Unexpected value 'Not allowed to use ShellScript'
32+
"Not allowed to use ShellScript": error
33+
${{ else }}:
34+
${{ pair.key }}: ${{ pair.value }}
35+
36+
- script: echo This happens after code
37+
displayName: 'Base: Signing'
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
# azure-pipelines.yml
2+
trigger:
3+
branches:
4+
include:
5+
- '*'
6+
7+
schedules:
8+
- cron: '0 1 * * *'
9+
displayName: 'Nightly build (UTC)'
10+
always: 'true'
11+
branches:
12+
include:
13+
- main
14+
15+
extends:
16+
template: template.yml
17+
parameters:
18+
usersteps:
19+
# - task: MyTask@1
20+
- bash: echo bash
21+
- script: echo This step will be stripped out and not run!
22+
- task: CmdLine@2
23+
displayName: Test - Will be stripped out
24+
inputs:
25+
script: echo This step will be stripped out and not run!
26+
# - task: MyOtherTask@2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
# template.yml
2+
parameters:
3+
- name: usersteps
4+
type: stepList
5+
default: []
6+
steps:
7+
# The first 3 lines will remove task CmdLine@2
8+
- ${{ each step in parameters.usersteps }}:
9+
- ${{ if ne(step.task, 'CmdLine@2') }}:
10+
- ${{ step }}
11+
# The lines below will replace task CmdLine@2
12+
- ${{ else }}:
13+
- ${{ each pair in step }}:
14+
${{ if eq(pair.key, 'inputs') }}:
15+
inputs:
16+
${{ each attribute in pair.value }}:
17+
${{ if eq(attribute.key, 'script') }}:
18+
script: echo "Script removed by template"
19+
${{ else }}:
20+
${{ attribute.key }}: ${{ attribute.value }}
21+
${{ elseif ne(pair.key, 'displayName') }}:
22+
${{ pair.key }}: ${{ pair.value }}
23+
24+
displayName: 'Disabled by template: ${{ step.displayName }}'

0 commit comments

Comments
 (0)