-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathazure-pipelines-develop.yml
214 lines (192 loc) · 7.55 KB
/
azure-pipelines-develop.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
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
### Develop Pipeline
### Snapshot Branch Versioning Stategy: X.X.X-SNAPSHOT
### Project :: kmdp-trisotech-asset-repository-service
# !! Downstream Build: knew-asset-factory !! #
trigger:
branches:
include:
- develop
exclude:
- feature*
paths:
exclude:
- azure-pipelines-develop.yml
- azure-pipelines-features.yml
- release-notes.md
- README.md
# Watches upstream build for success to run
resources:
pipelines:
- pipeline: kmdpTrisotechAssetRepositoryServiceDevelop
source: kmdpKnowledgebaseServiceDevelop
trigger:
branches:
- develop
- pipeline: kmdpTrisotechAssetRepositoryServiceDevelop
source: kmdpTrisotechAssetRepositoryServiceMain
trigger:
branches:
- develop
# Sets Virtual Machine to Run Pipeline on
pool:
vmImage: "ubuntu-latest"
# Gets Variables from Azure DevOps Library
variables:
- group: kmdp-platform-variables
- group: kmdp-platform-dev-variables
- group: kmd-veracode
# ------------------ PIPELINE STEPS ------------------
steps:
# Outputs pipeline steps have started
- script: |
echo Starting Develop Branch Build Pipeline!
echo Project :: kmdp-trisotech-asset-repository-service
displayName: "Starting Pipeline Steps"
# Reads Root pom.xml File
# Gets/Sets GAV from POM to Pipeline Variables
- task: PowerShell@2
displayName: "Get/Set POM Variables"
inputs:
targetType: "inline"
script: |
[xml]$pomXml = Get-Content .\pom.xml
Write-Host --------------------------------
Write-Host POM Variables:
Write-Host GroupId: $pomXml.project.groupId
Write-Host ArtifactId: $pomXml.project.artifactId
Write-Host Version: $pomXml.project.version
Write-Host --------------------------------
Write-Host Setting GAV to local task variables
$groupId=$pomXml.project.groupId
$artifactId=$pomXml.project.artifactId
$version=$pomXml.project.version
Write-Host --------------------------------
Write-Host Setting GAV to pipeline variables
Write-Host "##vso[task.setvariable variable=projectSnapShotVersion]$version"
Write-Host "##vso[task.setvariable variable=projectGroupId]$groupId"
Write-Host "##vso[task.setvariable variable=projectArtifactId]$artifactId"
# Gets .m2 Settings File from Azure DevOps Library
# Downloads File for use in Pipeline
- task: DownloadSecureFile@1
displayName: "Downloads Secure .m2 Settings File"
name: settingsxml
inputs:
secureFile: settings-dev.xml
# Write settings file to Build Server
- task: PowerShell@2
displayName: "Update m2 Settings File"
inputs:
targetType: "inline"
script: |
New-Item -Type Directory -Force "${HOME}/.m2"
Copy-Item -Force "$(settingsxml.secureFilePath)" "${HOME}/.m2/settings.xml"
# Authenticate to Maven Feed
- task: MavenAuthenticate@0
displayName: "Maven Authenticate"
inputs:
artifactsFeeds: "KMD"
# Sets JDK 11 for Pipeline
# Runs Maven Goal: validate
- task: Maven@3
displayName: "Sets Pipeline to JDK 11"
inputs:
mavenPomFile: "pom.xml"
goals: "validate"
options: "-ntp"
javaHomeOption: "JDKVersion"
jdkVersionOption: "1.11"
# SLM Versioning Policy (Preprod)
- task: AlmVersioning@4
displayName: "SLM Update Version and Build Number"
inputs:
projectType: java
versionFilePath: kmdp-trisotech-asset-repository-service-impl/pom.xml
versionTransformation: "preprod"
# Update Build Number by removing Snapshots
- task: PowerShell@2
displayName: "Update Build # Remove Snapshot"
inputs:
targetType: "inline"
script: |
Write-Host AfterSlmBuild: $Env:BUILD_BUILDNUMBER
$buildNumber = $Env:BUILD_BUILDNUMBER
$finalBuildNumber = $buildNumber.replace("-SNAPSHOT","")
Write-Host AfterSLMBuildRemoveSnap: $finalBuildNumber
Write-Host "##vso[build.updatebuildnumber]$finalBuildNumber"
env:
BUILD_BUILDNUMBER: $(build.buildNumber)
# Retrieve SLM preprod version
- task: PowerShell@2
displayName: "Retrieve SLM Preprod Version"
inputs:
targetType: "inline"
script: |
Write-Host ALM Version: $env:ALM_VERSION
$projectSlmVersion=$env:ALM_VERSION.replace("-SNAPSHOT","")
Write-Host Project Version: $projectSlmVersion
Write-Host "##vso[task.setvariable variable=projectSlmVersionFinal]$projectSlmVersion"
env:
ALM_VERSION: $(AlmVersioning.Project.Version)
# Set Version of Deployable War
- task: PowerShell@2
displayName: "Maven Set Version Deployable War"
inputs:
targetType: "inline"
script: |
mvn versions:set -pl kmdp-trisotech-asset-repository-service-impl "-DnewVersion=$env:PROJECT_SLM_VERSION" -ntp
env:
PROJECT_SLM_VERSION: $(projectSlmVersionFinal)
# Deploy maven using trisotech tokens
- task: PowerShell@2
displayName: "Maven Deploy"
inputs:
targetType: "inline"
script: |
mvn clean deploy "-Dspring.profiles.active=dev" "-DsplunkToken=$env:TRISO_SPLUNK_TOKEN" "-DaltDeploymentRepository=$env:DEPLOY_REPO::default::$env:DEPLOY_REPO_PATH" "-Dedu.mayo.kmdp.trisotechwrapper.trisotechToken=$env:TRISO_DEV_TOKEN" -ntp
env:
TRISO_DEV_TOKEN: $(trisoDevToken)
TRISO_SPLUNK_TOKEN: $(splunkToken)
DEPLOY_REPO: $(deploymentRepo)
DEPLOY_REPO_PATH: $(deploymentRepoPath)
# Write SLM version to variable group for trisotech war
- task: PowerShell@2
displayName: "Update Variable Group by Id"
inputs:
targetType: "inline"
script: |
# Write your PowerShell commands here.
$base64AuthInfo = [Convert]::ToBase64String([Text.Encoding]::ASCII.GetBytes(("{0}:{1}" -f "",$env:SYSTEM_ACCESSTOKEN)))
$url = "https://dev.azure.com/mclm/KMD/_apis/distributedtask/variablegroups/19?api-version=6.1-preview.1"
$variables = Invoke-RestMethod -Uri $url -Method Get -ContentType "application/json" -Headers @{Authorization=("Basic {0}" -f $base64AuthInfo)}
$variables.variables.trisoRepoWarVersion.value = $env:PROJECT_SLM_VERSION
$jsonFile = @($variables) | ConvertTo-Json -Depth 99
$pipeline = Invoke-RestMethod -Uri $url -Method Put -Body $jsonFile -ContentType "application/json" -Headers @{Authorization=("Basic {0}" -f $base64AuthInfo)}
Write-Host "New Variable Value:" $pipeline.variables.trisoRepoWarVersion.value
env:
SYSTEM_ACCESSTOKEN: $(system.accesstoken)
PROJECT_SLM_VERSION: $(projectSlmVersionFinal)
# Copy War File to build
- task: CopyFiles@2
displayName: "Copy Files to: $(build.artifactstagingdirectory)"
inputs:
SourceFolder: "$(system.defaultworkingdirectory)"
Contents: |
**/*.war
TargetFolder: "$(build.artifactstagingdirectory)"
# Export Variables
- task: ImportExportVariables@1
displayName: "Export Build Variables"
inputs:
action: "Export"
# Publish to Azure Pipelines
- task: PublishBuildArtifacts@1
displayName: "Publish Artifact: deploy"
inputs:
PathtoPublish: "$(build.artifactstagingdirectory)"
ArtifactName: deploy
condition: succeededOrFailed()
# ------------------ END PIPELINE ------------------
# Outputs pipeline steps have ended
- script: |
echo Ending Develop Branch Pipeline!
displayName: "Ending Pipeline Steps"