-
Notifications
You must be signed in to change notification settings - Fork 0
/
azure-pipelines.yml
129 lines (126 loc) · 4.62 KB
/
azure-pipelines.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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
variables:
- name: resource_group
value: tmc-bootstrap-automation
- name: storage_account
value: tfstate01tmc
- name: service_connection
value: warroyo-se-azure
- group: tmc-bootstrap-automation
trigger:
branches:
include:
- main
paths:
include:
- "cluster_yaml/*"
- "terraform/*"
pr: none
stages:
- stage: validate
jobs:
- job: validate
continueOnError: false
steps:
- checkout: self
- template: ./pipeline-templates/tf.yml
- task: TerraformTaskV4@4
displayName: 'validate'
inputs:
provider: 'azurerm'
command: 'validate'
- stage: plan
dependsOn: [validate]
condition: succeeded('validate')
jobs:
- job: terraform_plan
steps:
- checkout: self
- template: ./pipeline-templates/tf.yml
- task: TerraformTaskV4@4
displayName: 'plan'
inputs:
provider: 'azurerm'
command: 'plan'
environmentServiceNameAzureRM: $(service_connection)
workingDirectory: '$(System.DefaultWorkingDirectory)/terraform/'
- stage: apply
dependsOn: [plan]
condition: succeeded('plan')
jobs:
- job: terraform_apply
steps:
- checkout: self
- template: ./pipeline-templates/tf.yml
- task: TerraformTaskV4@4
displayName: 'apply'
inputs:
provider: 'azurerm'
command: 'apply'
environmentServiceNameAzureRM: $(service_connection)
workingDirectory: '$(System.DefaultWorkingDirectory)/terraform/'
- stage: template
dependsOn: [apply]
condition: succeeded('apply')
jobs:
- job: template_files
steps:
- checkout: self
persistCredentials: true
- task: UsePythonVersion@0
inputs:
versionSpec: '3.x'
- template: ./pipeline-templates/tf.yml
- task: TerraformTaskV4@4
displayName: 'output'
name: tfoutput
inputs:
provider: 'azurerm'
command: 'output'
environmentServiceNameAzureRM: $(service_connection)
workingDirectory: '$(System.DefaultWorkingDirectory)/terraform/'
- script: |
python -m pip install --upgrade pip
pip install copier
displayName: 'Install Python dependencies'
- task: PythonScript@0
inputs:
scriptSource: 'filePath'
scriptPath: '$(System.DefaultWorkingDirectory)/pipeline-scripts/generate-flux.py'
arguments: '$(tfoutput.jsonOutputVariablesPath)'
workingDirectory: '$(System.DefaultWorkingDirectory)/pipeline-scripts'
- script: |
git config --global user.email tmc-ado-automation@vmware.com & git config --global user.name "ado"
workingDirectory: $(System.DefaultWorkingDirectory)
- script: |
set -o errexit
git fetch --all
git add ./flux
if git diff --cached --exit-code flux/; then
echo "Nothing to commit"
echo "##vso[task.setvariable variable=doPR]No"
exit 0
fi
echo "committing new flux repo structure"
git checkout -b $(Build.BuildNumber)
git commit -m "generating flux repo structure $(Build.BuildNumber)"
git push --set-upstream origin $(Build.BuildNumber)
echo "##vso[task.setvariable variable=doPR]Yes"
displayName: push flux repo structure
workingDirectory: $(System.DefaultWorkingDirectory)
- script: |
curl -LO https://github.com/jenkins-x-plugins/jx-scm/releases/download/v0.2.41/jx-scm-linux-amd64.tar.gz
tar -xvf jx-scm-linux-amd64.tar.gz
./jx-scm pull-request create \
--kind "github" \
--server "https://github.com" \
--owner "warroyo" \
--name "tmc-bootstrap-automation" \
--head "$(Build.BuildNumber)" \
--title "tmc pipeline PR" \
--body "add new flux repo structure" \
--base "main" \
--allow-update
displayName: create PR
condition: and(succeeded(), eq(variables['doPr'], 'Yes'))
env:
GIT_TOKEN: $(github-pat)