-
Notifications
You must be signed in to change notification settings - Fork 0
/
Jenkinsfile
110 lines (110 loc) · 5.11 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
pipeline {
agent none
options {
disableResume()
}
stages {
stage('Build') {
agent { label 'master' }
steps {
echo "Aborting all running jobs ..."
script {
abortAllPreviousBuildInProgress(currentBuild)
}
echo "Building ..."
sh 'unset JAVA_OPTS; pipeline/gradlew --no-build-cache --console=plain --no-daemon -b pipeline/build.gradle cd-build -Pargs.--config=pipeline/config.groovy -Pargs.--pr=${CHANGE_ID}'
}
}
stage('Deploy (DEV)') {
agent { label 'master' }
steps {
echo "Deploy (DEV) ..."
sh 'unset JAVA_OPTS; pipeline/gradlew --no-build-cache --console=plain --no-daemon -b pipeline/build.gradle cd-deploy -Pargs.--config=pipeline/config.groovy -Pargs.--pr=${CHANGE_ID} -Pargs.--env=dev'
}
}
stage('Unit Tests and SonarQube Reporting (DEV)') {
agent { label 'master' }
steps {
echo "Running unit tests and reporting them to SonarQube ..."
sh 'unset JAVA_OPTS; pipeline/gradlew --no-build-cache --console=plain --no-daemon -b pipeline/build.gradle cd-unit-test -Pargs.--config=pipeline/config.groovy -Pargs.--pr=${CHANGE_ID} -Pargs.--env=dev -Pargs.--branch=${CHANGE_BRANCH}'
}
}
stage('Functional Test (DEV)') {
agent { label 'master' }
steps {
echo "Functional Test (DEV) ..."
sh 'unset JAVA_OPTS; pipeline/gradlew --no-build-cache --console=plain --no-daemon -b pipeline/build.gradle cd-functional-test -Pargs.--config=pipeline/config.groovy -Pargs.--pr=${CHANGE_ID} -Pargs.--env=dev'
}
}
stage ('ZAP (DEV)'){
agent { label 'master' }
steps {
echo "ZAP (DEV)"
sh 'unset JAVA_OPTS; pipeline/gradlew --no-build-cache --console=plain --no-daemon -b pipeline/build.gradle cd-zap -Pargs.--config=pipeline/config.groovy -Pargs.--pr=${CHANGE_ID} -Pargs.--env=dev'
}
}
stage('Deploy (TEST)') {
agent { label 'master' }
when {
environment name: 'CHANGE_TARGET', value: 'master'
}
steps {
echo "Deploy (TEST)"
sh 'unset JAVA_OPTS; pipeline/gradlew --no-build-cache --console=plain --no-daemon -b pipeline/build.gradle cd-deploy -Pargs.--config=pipeline/config.groovy -Pargs.--pr=${CHANGE_ID} -Pargs.--env=test'
}
}
stage('Deploy (PROD)') {
agent { label 'master' }
when {
environment name: 'CHANGE_TARGET', value: 'master'
}
steps {
script {
def IS_APPROVED = input(message: "Deploy to PROD?", ok: "yes", parameters: [string(name: 'IS_APPROVED', defaultValue: 'yes', description: 'Deploy to PROD?')])
if (IS_APPROVED != 'yes') {
currentBuild.result = "ABORTED"
error "User cancelled"
}
echo "Deploy (PROD)"
sh 'unset JAVA_OPTS; pipeline/gradlew --no-build-cache --console=plain --no-daemon -b pipeline/build.gradle cd-deploy -Pargs.--config=pipeline/config.groovy -Pargs.--pr=${CHANGE_ID} -Pargs.--env=prod'
}
}
}
stage('Merge to master') {
agent { label 'master' }
when {
environment name: 'CHANGE_TARGET', value: 'master'
}
steps {
script {
def IS_APPROVED = input(message: "Merge to master?", ok: "yes", parameters: [string(name: 'IS_APPROVED', defaultValue: 'yes', description: 'Merge to master?')])
if (IS_APPROVED != 'yes') {
currentBuild.result = "ABORTED"
error "User cancelled"
}
echo "Squashing commits and merging to master"
}
withCredentials([usernamePassword(credentialsId: 'github-account', passwordVariable: 'GIT_PASSWORD', usernameVariable: 'GIT_USERNAME')]) {
sh """
git fetch
git checkout ${CHANGE_TARGET}
git merge --squash origin/${CHANGE_BRANCH}
git commit -m "Merge branch '${CHANGE_BRANCH}' into ${CHANGE_TARGET}"
git push https://${GIT_USERNAME}:${GIT_PASSWORD}@github.com/bcgov/mds.git
"""
}
}
}
stage('Acceptance') {
agent { label 'master' }
input {
message "Should we continue with cleanup?"
ok "Yes!"
}
steps {
echo "Acceptance ..."
sh 'unset JAVA_OPTS; pipeline/gradlew --no-build-cache --console=plain --no-daemon -b pipeline/build.gradle cd-clean -Pargs.--config=pipeline/config.groovy -Pargs.--pr=${CHANGE_ID}'
}
}
}
}