This repository has been archived by the owner on Dec 2, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathJenkinsfile
71 lines (68 loc) · 2.71 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
pipeline {
agent none
options {
disableResume()
}
stages {
stage('Abort Previous') {
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)
}
}
}
stage('Deploy (DEV)') {
agent { label 'deploy' }
steps {
echo "Deploying ..."
sh "cd .pipeline && ./npmw ci && ./npmw run deploy -- --pr=${CHANGE_ID} --env=dev"
echo "Testing..."
//sh "cd .pipeline && ./npmw ci && ./npmw run test -- --pr=${CHANGE_ID} --env=dev"
}
}
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 "Backing up..."
sh "oc project cailey-test && oc create job --from cronjob/backup-mongo-test backup-mongo-${CHANGE_ID}-${currentBuild.number}"
echo "Deploying ..."
sh "cd .pipeline && ./npmw ci && ./npmw run deploy -- --pr=${CHANGE_ID} --env=prod"
echo "Testing..."
//sh "cd .pipeline && ./npmw ci && ./npmw run test -- --pr=${CHANGE_ID} --env=prod"
}
}
stage('Cleanup (DEV)') {
agent { label 'deploy' }
input {
message "Should we continue with cleanup of DEV?"
ok "Yes!"
}
steps {
echo "Cleaning up..."
sh "oc project cailey-dev"
sh "oc delete all,configmap,secret -l app=code-test-dev-${CHANGE_ID}"
sh "oc delete all -l app=rocketchat-dev-${CHANGE_ID}"
sh "oc delete pvc -l statefulset=mongodb-dev-${CHANGE_ID}"
}
}
}
}