This repository has been archived by the owner on Sep 2, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 14
/
Copy pathJenkinsfile-dev
179 lines (164 loc) · 6.28 KB
/
Jenkinsfile-dev
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
#!groovy
@Library('jenkins-pipeline-shared') _
pipeline {
environment {
DEPLOY_NAME = "dev"
GIT_TYPE = "Github"
GITLAB_CREDS = "ai-gitlab-credentials"
ORGANIZATION = "ons"
TEAM = "ai"
MODULE_NAME = "address-index-api"
CF_MODULE_NAME = "addressindex-api"
GATLING_REQUESTS_PER_SECOND = 20
GATLING_GET_ENDPOINT = "https://addressindex-api-${DEPLOY_NAME}.apps.cf1.ons.statistics.gov.uk/addresses?input=26%20FROG%20LANE%20TITCHFIELD%20PO144DU"
}
options {
skipDefaultCheckout()
buildDiscarder(logRotator(numToKeepStr: '30', artifactNumToKeepStr: '30'))
timeout(time: 30, unit: 'MINUTES')
timestamps()
}
agent any
stages {
stage('Checkout') {
agent any
steps {
deleteDir()
checkout scm
stash name: 'app'
sh "$SBT version"
script {
version = '1.0.' + env.BUILD_NUMBER
currentBuild.displayName = version
env.NODE_STAGE = "Checkout"
}
}
}
stage('Build') {
agent any
steps {
colourText("info", "Building ${env.BUILD_ID} on ${env.JENKINS_URL} from branch ${env.BRANCH_NAME}")
script {
env.NODE_STAGE = "Build"
sh '''
$SBT "project address-index-server" clean compile universal:packageBin
'''
stash name: 'compiled'
}
}
}
stage('Static Analysis') {
agent any
steps {
parallel(
"Unit": {
colourText("info", "Running unit tests and coverage")
sh "$SBT \"project address-index-server\" coverage test coverageReport"
},
"Style": {
colourText("info", "Running style tests")
sh """
$SBT \"project address-index-server\" scalastyle
"""
},
"Additional": {
colourText("info", "Running additional tests")
sh "$SBT \"project address-index-server\" scapegoat"
}
)
}
post {
always {
script {
STAGE = "Static Analysis"
}
}
success {
colourText("info", "Generating reports for tests")
// junit '**/target/test-reports/*.xml'
step([$class: 'CoberturaPublisher', coberturaReportFile: '**/server/target/scala-2.12/coverage-report/*.xml'])
step([$class: 'CheckStylePublisher', pattern: 'server/target/scalastyle-result.xml, server/target/scala-2.12/scapegoat-report/scapegoat-scalastyle.xml'])
}
failure {
colourText("warn", "Failed to retrieve reports.")
}
}
}
// bundle all libs and dependencies
stage('Bundle') {
agent any
steps {
script {
env.NODE_STAGE = "Bundle"
}
colourText("info", "Bundling....")
dir('conf') {
git(url: "$GITLAB_URL/AddressIndex/${MODULE_NAME}.git", credentialsId: GITLAB_CREDS, branch: "master")
}
}
}
stage('Deploy') {
agent any
steps {
script {
env.NODE_STAGE = "Deploy"
}
milestone(1)
lock('Deployment Initiated') {
colourText("info", 'deployment in progress')
deploy()
colourText("success", 'Deploy.')
}
}
}
stage('Integration Tests') {
agent any
steps {
script {
env.NODE_STAGE = "Integration Tests"
}
unstash 'compiled'
sh "$SBT -DREQUESTS_PER_SECOND=$GATLING_REQUESTS_PER_SECOND -DBASE_URL=$GATLING_GET_ENDPOINT \"project address-index-server\" gatling-it:test"
colourText("success", 'Integration Tests - For Release or Dev environment.')
}
}
}
post {
always {
script {
colourText("info", 'Post steps initiated')
deleteDir()
}
}
success {
colourText("success", "All stages complete. Build was successful.")
sendNotifications currentBuild.result, "\$AI_EMAIL_LIST"
}
unstable {
colourText("warn", "Something went wrong, build finished with result ${currentResult}. This may be caused by failed tests, code violation or in some cases unexpected interrupt.")
sendNotifications currentBuild.result, "\$AI_EMAIL_LIST", "${env.NODE_STAGE}"
}
failure {
colourText("warn", "Process failed at: ${env.NODE_STAGE}")
sendNotifications currentBuild.result, "\$AI_EMAIL_LIST", "${env.NODE_STAGE}"
}
}
}
def deploy() {
deploymentName = "${env.DEPLOY_NAME}"
credentialsId = "${TEAM}-${deploymentName}-cf" // ai-dev-cf
CF_ORG = "${TEAM}".toUpperCase() // AI
CF_SPACE = "${deploymentName}".capitalize() // eg Dev
appName = "${CF_MODULE_NAME}-${deploymentName}" // addressindex-api-dev
appPath = "server/target/universal/address-index-server.zip"
manifestPath = "conf/${deploymentName}/manifest.yml" // conf/dev/manifest.yml
echo "Deploying Api app to ${deploymentName}"
echo "Deployment params : \n" +
"credentialsId : " + credentialsId +
"CF_ORG : " + CF_ORG +
"CF_SPACE : " + CF_SPACE +
"appName : " + appName +
"appPath : " + appPath +
"manifestPath : " + manifestPath
deployToCloudFoundry(credentialsId, "${CF_ORG}", "${CF_SPACE}", appName, appPath, manifestPath)
}