This repository has been archived by the owner on Jan 13, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 31
/
Copy pathbasicPipeline.groovy
83 lines (68 loc) · 3.14 KB
/
basicPipeline.groovy
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
/*
* References:
* - https://zwischenzugs.com/2017/04/23/things-i-wish-i-knew-before-using-jenkins-pipelines/
* - https://jenkins.io/blog/2017/10/02/pipeline-templates-with-shared-libraries/
* - https://jenkins.io/doc/pipeline/examples/
*/
import hudson.model.Result;
import jenkins.model.CauseOfInterruption.UserInterruption;
import org.kohsuke.github.*
import bcgov.OpenShiftHelper
import bcgov.GitHubHelper
def call(body) {
def context= [:]
body.resolveStrategy = Closure.DELEGATE_FIRST
body.delegate = context
body()
properties([
buildDiscarder(logRotator(artifactDaysToKeepStr: '', artifactNumToKeepStr: '', daysToKeepStr: '', numToKeepStr: '10')),
durabilityHint('MAX_SURVIVABILITY'),
parameters([string(defaultValue: '', description: '', name: 'run_stages')])
])
stage('Prepare') {
abortAllPreviousBuildInProgress(currentBuild)
echo "BRANCH_NAME=${env.BRANCH_NAME}\nCHANGE_ID=${env.CHANGE_ID}\nCHANGE_TARGET=${env.CHANGE_TARGET}\nBUILD_URL=${env.BUILD_URL}"
//def pullRequest=GitHubHelper.getPullRequest(this)
//echo "Pull-Request: ${pullRequest}"
//echo "Pull-Request: head.ref: ${pullRequest.getHead().getRef()}"
}
stage('Build') {
node('build') {
checkout scm
new OpenShiftHelper().build(this, context)
if ("master".equalsIgnoreCase(env.CHANGE_TARGET)) {
new OpenShiftHelper().prepareForCD(this, context)
}
}
}
for(String envKeyName: context.env.keySet() as String[]){
String stageDeployName=envKeyName.toUpperCase()
if ("DEV".equalsIgnoreCase(stageDeployName) || "master".equalsIgnoreCase(env.CHANGE_TARGET)) {
stage("Readiness - ${stageDeployName}") {
node('build') {
new OpenShiftHelper().waitUntilEnvironmentIsReady(this, context, envKeyName)
}
}
}
if (!"DEV".equalsIgnoreCase(stageDeployName) && "master".equalsIgnoreCase(env.CHANGE_TARGET)){
stage("Approve - ${stageDeployName}") {
def inputResponse = input(id: "deploy_${stageDeployName.toLowerCase()}", message: "Deploy to ${stageDeployName}?", ok: 'Approve', submitterParameter: 'approved_by')
//echo "inputResponse:${inputResponse}"
GitHubHelper.getPullRequest(this).comment("User '${inputResponse}' has approved deployment to '${stageDeployName}'")
}
}
if ("DEV".equalsIgnoreCase(stageDeployName) || "master".equalsIgnoreCase(env.CHANGE_TARGET)){
stage("Deploy - ${stageDeployName}") {
node('build') {
new OpenShiftHelper().deploy(this, context, envKeyName)
}
}
}
}
stage('Cleanup') {
def inputResponse=input(id: 'close_pr', message: "Ready to Accept/Merge, and Close pull-request #${env.CHANGE_ID}?", ok: 'Yes', submitter: 'authenticated', submitterParameter: 'approver')
echo "inputResponse:${inputResponse}"
new OpenShiftHelper().cleanup(this, context)
GitHubHelper.mergeAndClosePullRequest(this)
}
}