-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathJenkinsfile
90 lines (84 loc) · 2.89 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
@Library("devops") _
def ocp = new cicd.ocp()
def git_tool = new cicd.github()
def postStep = new cicd.postStep()
def common = new cicd.common()
def buildAndTest = new cicd.buildAndTest()
def init = new cicd.init()
pipeline {
agent none
options { skipDefaultCheckout true }
stages {
stage('Initialize'){
agent { docker { image "${init.docker_image('common')}" } }
steps {
cleanWs()
// Clone git repository
script {
def branch_name = ""
if ( params.ACTION == "build" ) {
branch_name = "refs/heads/${params.BRANCH}"
} else {
branch_name = params.COMMIT_SHA
}
checkout()
sh "ls -l"
cfg = init.config()
init.set_env_vars(cfg)
// Initialize status variables
result = "SUCCESS"
job_stage = "${STAGE_NAME}"
gate_status = "OK"
error_message = 'None'
}
}
}
stage('Build and Test') {
when { expression { common.stage_conditions("build", cfg, result) } }
agent {
docker {
image cfg.get("build_image_name")
args cfg.get('docker_args')
}
}
steps {
script {
// Store stage name to send to Slack
job_stage = "${STAGE_NAME}"
// Regardless of the junit test results, procceed.
( result, error_message ) = buildAndTest.exec(cfg)
}
}
}
stage("OpenShift") {
when { expression { common.stage_conditions("ocp", cfg, result) } }
agent { docker { image "${init.docker_image('common')}" } }
steps {
script {
envs = ['dev', 'stg', 'prod']
for (env in envs) {
stage(env) {
if ( common.stage_conditions(env, cfg, result) ) {
// Store stage name to send to Slack
job_stage = "${STAGE_NAME}"
( result, error_message ) = ocp.orchestrate(env, cfg)
}
}
}
}
}
}
}
post {
always {
script {
currentBuild.result = result
cfg.put("gate_status", gate_status)
cfg.put("job_stage", job_stage)
cfg.put("error_message", error_message)
cfg.put("result", result)
postStep.orchestrate(cfg)
}
}
}
}