-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathazure-pipelines.yml
197 lines (192 loc) · 6.24 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
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
trigger:
branches:
include:
- main
variables:
- group: vgTerraform
stages:
- stage: 'BuildTest'
displayName: 'Build and Test'
variables:
GOVERSION: '1.15.6' # Version of Go tools used for building and testing
CGO_ENABLED: '0' # Disable cgo to get a static binary
GOOS: 'linux'
GOARCH: 'amd64'
jobs:
- job: BuildTestBackend
displayName: 'Build and Test Go Backend'
pool:
vmImage: 'ubuntu-latest'
steps:
- task: GoTool@0
inputs:
version: $(GOVERSION)
displayName: 'Install and select Go version $(GOVERSION)'
- script: |
# Get tools for converting Go's test reports
go get -u github.com/jstemmer/go-junit-report 2>&1
go get -u github.com/axw/gocov/gocov 2>&1
go get -u github.com/AlekSi/gocov-xml 2>&1
# Run Go tests and turn output into JUnit test result format
go test ./cmd -v -coverprofile=devops-coverage.txt -covermode count 2>&1 | $HOME/go/bin/go-junit-report > devops-report.xml
rc=${PIPESTATUS[0]} # Get result code of `go test`
# Convert coverage file into XML
$HOME/go/bin/gocov convert devops-coverage.txt > devops-coverage.json
$HOME/go/bin/gocov-xml < devops-coverage.json > devops-coverage.xml
# Check if `go test` had an error
if [ $rc -ne 0 ]; then
# Let script fail by writing to stderr
>&2 echo "Tests failed"
fi
displayName: 'Run unit tests and convert results'
failOnStderr: true
- task: PublishTestResults@2
condition: always()
inputs:
testResultsFormat: 'JUnit'
testResultsFiles: '*report*.xml'
searchFolder: '$(Build.SourcesDirectory)'
displayName: 'Publish test results'
- task: PublishCodeCoverageResults@1
condition: always()
inputs:
codeCoverageTool: 'Cobertura'
summaryFileLocation: '$(Build.SourcesDirectory)/demo-coverage.xml'
displayName: 'Publish code coverage results'
- stage: 'Build'
displayName: 'Build'
jobs:
- job: Job
pool:
vmImage: 'ubuntu-latest'
steps:
# Create a variable
- script: echo "##vso[task.setvariable variable=tag;isOutput=true]${BUILD_SOURCEVERSION:0:8}"
name: setTagStep
- script: echo $(setTagStep.tag)
name: echovar
- script: |
sed -ie "s/#{tag}/$(setTagStep.tag)/g" Deploy.yaml
cp Deploy.yaml Deploy-prd.yaml
cat Deploy.yaml
displayName: 'Completando Deploy.yaml'
- task: Docker@2
inputs:
containerRegistry: 'ibm-cloud-cr'
repository: ws-rest/api-devops
command: 'buildAndPush'
tags: '$(setTagStep.tag)'
- task: CopyFiles@2
inputs:
contents: '*.yaml'
targetFolder: $(Build.ArtifactStagingDirectory)
- task: PublishPipelineArtifact@1
inputs:
targetPath: 'tf-cluster'
artifactName: 'terraform'
- stage: 'UpdateFunctionsIBMCloud'
displayName: 'Update Functions IBMCloud'
jobs:
- deployment: DeployFunctions
displayName: Job
pool:
vmImage: 'ubuntu-latest'
environment: Functions IBMCloud SPSA
strategy:
runOnce:
deploy:
steps:
- task: ArchiveFiles@2
displayName: 'Create file tar'
inputs:
rootFolderOrFile: '$(Pipeline.Workspace)/terraform'
includeRootFolder: false
archiveType: tar
tarCompression: none
archiveFile: '$(Pipeline.Workspace)/terraform.tar'
verbose: true
- task: ibmcloud-install@1
displayName: Install IBM CLI
inputs:
ibmcloudVersion: '1.2'
- task: ibmcloud-schematics@1
displayName: Execute Update
inputs:
ibmcloud-service: 'sp-azure-devops'
idworkspace: $(idworkspace)
ActionType: 'Update'
directorypath: '$(Pipeline.Workspace)/terraform.tar'
idtemplate: $(idtemplate)
- stage: 'Plan'
displayName: 'Plan IBM Install Cli'
jobs:
- job: Job
pool: Server
steps:
- task: Delay@1
displayName: Execute Plan
inputs:
delayForMinutes: '1'
- stage: Apply
jobs:
- deployment: DeployFunctions
displayName: Job
pool:
vmImage: 'ubuntu-latest'
environment: Functions IBMCloud SPSA
strategy:
runOnce:
deploy:
steps:
- task: ibmcloud-install@1
displayName: Install IBM CLI
inputs:
ibmcloudVersion: '1.2'
- task: ibmcloud-schematics@1
displayName: Execute apply
inputs:
ibmcloud-service: 'sp-azure-devops'
idworkspace: $(idworkspace)
ActionType: 'Apply'
- stage: 'PlanEjecucionApplyTerraform'
displayName: 'Plan ejecucion apply Terraform'
jobs:
- job: Job
pool: Server
steps:
- task: Delay@1
displayName: Execute Plan
inputs:
delayForMinutes: '5'
- stage: 'DeployApi'
displayName: 'Deploy Api'
jobs:
- deployment: DeployApi
displayName: Job
pool:
vmImage: 'ubuntu-latest'
environment: Deploy Api
strategy:
runOnce:
deploy:
steps:
- task: Kubernetes@1
displayName: secretType generic with literal values
inputs:
connectionType: 'Kubernetes Service Connection'
kubernetesServiceEndpoint: 'clusterDevopsIbm'
command: 'apply'
secretType: 'dockerRegistry'
secretArguments: --docker-server=us.icr.io --docker-username='11' --docker-password='1-1'
containerRegistryType: 'Container Registry'
dockerRegistryEndpoint: 'ibm-cloud-cr'
secretName: 'ibm-cloud-cr'
- task: Kubernetes@1
displayName: kubectl apply using arguments
inputs:
connectionType: 'Kubernetes Service Connection'
kubernetesServiceEndpoint: 'clusterDevopsIbm'
command: 'apply'
arguments: '-f artefacto/drop/Deploy.yaml'
secretType: 'dockerRegistry'
containerRegistryType: 'Container Registry'