-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathJenkinsfile
219 lines (209 loc) · 6.46 KB
/
Jenkinsfile
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
215
216
217
218
219
/**
Jenkinsfile: TradeDesk
This file is for CI pipeline mode
*/
@NonCPS
def getChanges() {
def changeLogSets = currentBuild.changeSets
def versionChanges = "<h4>Release Notes</h4>"
for (int i = 0; i < changeLogSets.size(); i++) {
def entries = changeLogSets[i].items
for (int j = 0; j < entries.length; j++) {
def entry = entries[j]
versionChanges += "<p>${entry.msg}<br>"
versionChanges += "<em>By ${entry.author}</em> on ${new Date(entry.timestamp)}</p>"
}
}
return versionChanges
}
pipeline {
agent {
node {
/**
Jenkins has a tendancy to build in a rather long path
We're using this to make it shorter as there are build issues when using long paths
*/
label 'jenkins.vtfs.cloud'
customWorkspace 'f:\\Jenkins-Builds\\vt.node.merj'
}
}
options {
disableConcurrentBuilds()
}
triggers {
/**
TODO: probably best to use a hook here
*/
pollSCM('*/5 * * * *')
}
stages {
stage('Slack Notification') {
steps {
slackSend (color: '#FFFF00', message: "STARTED: Job '${env.JOB_NAME} [${env.BUILD_NUMBER}]' (${env.BUILD_URL})")
}
}
stage("Git Version") {
steps {
script {
bat """
gitversion /output json > gitversion.json
"""
}
}
}
stage('Code Artifact Login') {
steps {
script {
withCredentials([usernamePassword(credentialsId: 'AWS', usernameVariable: 'AWS_ACCESS_KEY_ID', passwordVariable: 'AWS_SECRET_ACCESS_KEY')]){
env.AWS_DEFAULT_REGION = "eu-west-1"
bat """
aws codeartifact login --tool npm --domain vt --domain-owner 123296566209 --repository npm
"""
}
}
}
}
stage("Yarn Version") {
steps {
script {
bat """
yarn -v
"""
}
}
}
stage("Clean Cache") {
steps {
script {
bat """
yarn cache clean
"""
}
}
}
stage("Install Dependencies") {
steps {
script {
bat """
yarn install
"""
}
}
}
stage('Build and push zip to Octo') {
steps {
script {
bat """
yarn run build
"""
}
script {
bat """
yarn run export
"""
}
script {
def gitVersion = readJSON( file: 'gitversion.json' )
env.version = gitVersion["LegacySemVerPadded"]
env.versionAppend = ""
if(env.BRANCH_NAME == 'master') {
env.channel = "Master"
env.versionAppend = "." + env.BUILD_NUMBER
}
if(env.BRANCH_NAME.startsWith("feature/")) {
env.channel = "Feature"
env.versionAppend = "." + env.BUILD_NUMBER
}
if(env.BRANCH_NAME == 'develop') {
env.channel = "Develop"
env.versionAppend = "." + env.BUILD_NUMBER
}
if(env.BRANCH_NAME.startsWith("hotfix/")) {
env.channel = "Hotfix"
env.versionAppend = "." + env.BUILD_NUMBER
}
if(env.BRANCH_NAME.startsWith("release/")) {
env.channel = "Release"
env.versionAppend = "." + env.BUILD_NUMBER
}
if(env.BRANCH_NAME.startsWith("direct/")) {
env.channel = "Master"
env.versionAppend = "." + env.BUILD_NUMBER
}
env.zipFile = "VT.Node.Merj.${env.version}${env.versionAppend}.zip"
zip(dir: 'out', glob: '', zipFile: env.zipFile)
withCredentials([string(credentialsId: 'OctopusApiKey', variable: 'APIKey')]) {
bat """
echo Creating a release of ${env.JOB_NAME} on octopus in channel ${env.channel} with version ${env.version}
"E:\\Octopus\\CommandLine\\Octo.exe" push --package ${env.zipFile} --replace-existing --enableServiceMessages --server https://octopus.vtfs.cloud/ --apiKey ${APIKey}
"""
}
slackSend (color: '#44DF0A', message: "Version '${env.version}${env.versionAppend}' of '${env.JOB_NAME}' is now available in the octopus.vtfs.cloud library")
}
}
}
stage ('Create a Release on Octopus') {
steps {
script {
def gitVersion = readJSON( file: 'gitversion.json' )
env.version = gitVersion["LegacySemVerPadded"]
if(env.BRANCH_NAME == 'master') {
env.channel = "Master"
env.versionAppend = "." + env.BUILD_NUMBER
}
if(env.BRANCH_NAME.startsWith("feature/")) {
env.channel = "Feature"
env.versionAppend = "." + env.BUILD_NUMBER
}
if(env.BRANCH_NAME == 'develop') {
env.channel = "Develop"
env.versionAppend = "." + env.BUILD_NUMBER
}
if(env.BRANCH_NAME.startsWith("hotfix/")) {
env.channel = "Hotfix"
env.versionAppend = "." + env.BUILD_NUMBER
}
if(env.BRANCH_NAME.startsWith("release/")) {
env.channel = "Release"
env.versionAppend = "." + env.BUILD_NUMBER
}
if(env.BRANCH_NAME.startsWith("direct/")) {
env.channel = "Master"
env.versionAppend = "." + env.BUILD_NUMBER
}
if(env.channel) {
withCredentials([string(credentialsId: 'OctopusApiKey', variable: 'APIKey')]) {
bat """
echo Creating a release of ${env.JOB_NAME} on octopus in channel ${env.channel} with version ${env.version}
"E:\\Octopus\\CommandLine\\Octo.exe" create-release --ignoreexisting --project "Merj - Public" --packageVersion ${env.version}${env.versionAppend} --version ${env.version}${env.versionAppend} --server https://octopus.vtfs.cloud/ --channel ${env.channel} --apiKey ${APIKey}
"""
}
slackSend (color: '#44DF0A', message: "Created release '${env.version}${env.versionAppend}' on octopus in channel ${env.channel}")
}
else {
slackSend (color: '#EBEE00', message: "Not creating a release on octo for this version (${env.version}) as there is no channel (probably a feature branch)")
bat """
echo Not creating a release on octo for this version (${env.version}) as there is no channel (probably a feature branch)
"""
}
}
}
}
}
post {
always {
// this cleans up, if you want to test a build
// on the build server comment this and jump into the customWorkspace defined above..
cleanWs()
}
success {
slackSend (color: '#16CD00', message: "Success: '${env.JOB_NAME} [${env.BUILD_NUMBER}]'")
}
failure {
slackSend (color: '#FE031A', message: "Error building: Job '${env.JOB_NAME} [${env.BUILD_NUMBER}]' please check the console at (${env.BUILD_URL})")
}
unstable {
slackSend (color: '#FEBD03', message: "Build success but there were some warnings: Job '${env.JOB_NAME} [${env.BUILD_NUMBER}]' please check the console at (${env.BUILD_URL})")
}
}
}