-
Notifications
You must be signed in to change notification settings - Fork 1
/
Jenkinsfile
123 lines (121 loc) · 5.76 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
pipeline {
agent none
options {
disableResume()
}
stages {
stage('Verify-Files') {
agent { label 'master' }
steps {
echo "Aborting all running jobs ..."
script {
// Kill any running jobs
abortAllPreviousBuildInProgress(currentBuild)
// Grab any files under the pipeline directory
// Verify they match the trusted version
// files = findFiles(glob: 'openshift/pipeline/**')
// for (def file : files) {
// readTrusted file.path
// }
}
}
}
stage('Build') {
agent { label 'master' }
steps {
echo "Building ..."
sh 'unset JAVA_OPTS; openshift/pipeline/gradlew --no-build-cache --console=plain --no-daemon -b openshift/pipeline/build.gradle cd-build -Pargs.--config=openshift/pipeline/config-build.groovy -Pargs.--pr=${CHANGE_ID}'
}
}
stage('Deploy (DEV)') {
agent { label 'master' }
steps {
echo "Deploy (DEV) ..."
sh 'unset JAVA_OPTS; openshift/pipeline/gradlew --no-build-cache --console=plain --no-daemon -b openshift/pipeline/build.gradle cd-deploy -Pargs.--config=openshift/pipeline/config-dev.groovy -Pargs.--pr=${CHANGE_ID} -Pargs.--env=dev'
}
}
stage ('ZAP (DEV)'){
agent { label 'master' }
steps {
echo "ZAP (DEV)"
sh 'unset JAVA_OPTS; openshift/pipeline/gradlew --no-build-cache --console=plain --no-daemon -b openshift/pipeline/build.gradle cd-zap -Pargs.--config=openshift/pipeline/config-dev.groovy -Pargs.--pr=${CHANGE_ID} -Pargs.--env=dev'
}
}
stage('Deploy (TEST)') {
agent { label 'master' }
when {
environment name: 'CHANGE_TARGET', value: 'master'
}
steps {
script {
def IS_APPROVED = input(message: "Deploy to TEST?", ok: "yes", parameters: [string(name: 'IS_APPROVED', defaultValue: 'yes', description: 'Deploy to TEST?')])
if (IS_APPROVED != 'yes') {
currentBuild.result = "ABORTED"
error "User cancelled"
}
echo "Deploy (TEST)"
sh 'unset JAVA_OPTS; openshift/pipeline/gradlew --no-build-cache --console=plain --no-daemon -b openshift/pipeline/build.gradle cd-deploy -Pargs.--config=openshift/pipeline/config-test.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; openshift/pipeline/gradlew --no-build-cache --console=plain --no-daemon -b openshift/pipeline/build.gradle cd-deploy -Pargs.--config=openshift/pipeline/config-prod.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 """
# Update master with latest changes from develop
git checkout master
git fetch
git merge --squash origin/develop
git commit -m "Merge branch develop into master"
git push https://${GIT_USERNAME}:${GIT_PASSWORD}@github.com/bcgov/dormant-site-reclamation-program.git
# Update the HEAD on develop to be the same as master
git checkout develop
git fetch
git merge -s ours -m "Updating develop with master" origin/master
git push https://${GIT_USERNAME}:${GIT_PASSWORD}@github.com/bcgov/dormant-site-reclamation-program.git
"""
}
}
}
stage('Acceptance') {
agent { label 'master' }
input {
message "Should we continue with cleanup?"
ok "Yes!"
}
steps {
echo "Acceptance ..."
sh 'unset JAVA_OPTS; openshift/pipeline/gradlew --no-build-cache --console=plain --no-daemon -b openshift/pipeline/build.gradle cd-clean -Pargs.--config=openshift/pipeline/config-dev.groovy -Pargs.--pr=${CHANGE_ID}'
}
}
}
}