forked from bcgov/agri-nmp
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Jenkinsfile
94 lines (94 loc) · 3.56 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
pipeline {
agent none
options {
disableResume()
}
stages {
stage('Build') {
agent { label 'build' }
steps {
script {
def filesInThisCommitAsString = sh(script:"git diff --name-only HEAD~1..HEAD | grep -v '^.jenkins/' || echo -n ''", returnStatus: false, returnStdout: true).trim()
def hasChangesInPath = (filesInThisCommitAsString.length() > 0)
echo "${filesInThisCommitAsString}"
if (!currentBuild.rawBuild.getCauses()[0].toString().contains('UserIdCause') && !hasChangesInPath){
currentBuild.rawBuild.delete()
error("No changes detected in the path ('^.jenkins/')")
}
}
echo "Aborting all running jobs ..."
script {
abortAllPreviousBuildInProgress(currentBuild)
}
echo "Building ..."
sh "cd .pipeline && ./npmw ci && ./npmw run build -- --pr=${CHANGE_ID}"
}
}
stage('Deploy (DEV)') {
agent { label 'deploy' }
steps {
echo "Deploying ..."
sh "cd .pipeline && ./npmw ci && ./npmw run deploy -- --pr=${CHANGE_ID} --env=dev"
}
}
stage('Deploy (TEST)') {
agent { label 'deploy' }
when {
expression { return env.CHANGE_TARGET == 'master';}
beforeInput true
}
input {
message "Should we continue with deployment to TEST?"
ok "Yes!"
}
steps {
echo "Deploying ..."
sh "cd .pipeline && ./npmw ci && ./npmw run deploy -- --pr=${CHANGE_ID} --env=test"
}
}
stage('Deploy (PROD)') {
agent { label 'deploy' }
when {
expression { return env.CHANGE_TARGET == 'master';}
beforeInput true
}
input {
message "Should we continue with deployment to PROD?"
ok "Yes!"
}
steps {
echo "Deploying ..."
sh "cd .pipeline && ./npmw ci && ./npmw run deploy -- --pr=${CHANGE_ID} --env=prod"
}
}
stage('Accept Pull Request?') {
agent { label 'deploy' }
input {
message "Ready to Accept/Merge, and Close pull-request?"
ok "Yes!"
submitter 'authenticated'
submitterParameter "APPROVED_BY"
parameters {
choice(name: 'MERGE_METHOD', choices: ((env.CHANGE_TARGET == 'master')?['merge', 'squash']:['squash', 'merge']), description: '')
}
}
steps {
script{
bcgov.GitHubHelper.mergeAndClosePullRequest(this, "${MERGE_METHOD}")
}
}
}
stage('Cleanup PR artifacts') {
agent { label 'deploy' }
input {
message "Should we continue with removing PR based artifacts from build and dev namespaces?"
ok "Yes!"
}
steps {
echo "Removing PR based artifacts from DEV namespace ..."
sh "cd .pipeline && ./npmw ci && ./npmw run clean -- --pr=${CHANGE_ID} --env=build"
sh "cd .pipeline && ./npmw ci && ./npmw run clean -- --pr=${CHANGE_ID} --env=dev"
}
}
}
}