-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathjob-trigger-pipeline-multiple-times.yml
52 lines (49 loc) · 2.43 KB
/
job-trigger-pipeline-multiple-times.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
# Version 1.0
# Creator: Mika Haapsaari & Pawel Lukasiak
# Description: This template triggers another pipeline a defined number of times.
# Can be used for example to trigger a resource deployment pipeline with an identical set of parameters.
#
# Parameters:
# environment - Azure DevOps defined deployment environment
# pipelinesSecurityToken [required] - PAT token that has read and execute pipeline access
# devOpsOrganization [required] - URI of the Azure DevOps Organisation
# devOpsProject [required] - name of the Azure DevOps project
# devOpsPipeline [required] - name of the pipeline to be triggered
# numberOfDeployments [required] - integer for pipeline trigger
parameters:
environment: default-environment
pipelinesSecurityToken: ""
devOpsOrganization: ""
devOpsProject: ""
devOpsPipeline: ""
numberOfDeployments: 2
jobs:
- deployment: deploy
timeoutInMinutes: 120
displayName: Deploy pipeline multiple times
pool:
vmImage: 'ubuntu-latest'
environment: ${{ parameters.environment }}
strategy:
runOnce:
deploy:
steps:
- script: |
echo Organization ${{parameters.devOpsOrganization}}
echo Project ${{parameters.devOpsProject}}
echo Pipeline ${{parameters.devOpsPipeline}}
export AZURE_DEVOPS_EXT_PAT=${{parameters.pipelinesSecurityToken}}
export BUILD_DEFINITION=`az pipelines build definition list --name '${{parameters.devOpsPipeline}}' --org '${{parameters.devOpsOrganization}}' --project '${{parameters.devOpsProject}}' | jq -r '.[].id'`
echo BuildDefinition ${BUILD_DEFINITION}
export DEV_OPS_PROJECT='${{parameters.devOpsProject}}'
echo DevOpsProject ${DEV_OPS_PROJECT}
export DEV_OPS_PROJECT_NOSPACES=${DEV_OPS_PROJECT/ /%20}
echo DevOpsProjectNoSpaces ${DEV_OPS_PROJECT_NOSPACES}
for (( i=1; i<=${{parameters.numberOfDeployments}}; i++ ))
do
curl -X POST ${{parameters.devOpsOrganization}}/${DEV_OPS_PROJECT_NOSPACES}/_apis/pipelines/${BUILD_DEFINITION}/runs\?api-version\=6.0-preview.1 \
-H "Content-Type: application/json" \
-u "${AZURE_DEVOPS_EXT_PAT}": \
-d '{"stagesToSkip": [],"templateParameters": {"parameter": "${{parameters.parametervalue}}"},"variables": {}}'
done
displayName: 'Queue pipeline ${{parameters.numberOfDeployments}} time(s)'