-
Notifications
You must be signed in to change notification settings - Fork 1
/
SITJenkinsfile
69 lines (68 loc) · 2.94 KB
/
SITJenkinsfile
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
#!bash
pipeline {
agent {
label 'docker'
}
environment {
appName = "sample-app"
buildconf = "false"
dc = "false"
DEV_NAMESPACE = "dev"
SIT_NAMESPACE = "sit"
DEV_API_SERVER= "https://api.cluster-89e8.89e8.sandbox1804.opentlc.com:6443"
}
stages {
stage('Promote Image in SIT Namespace') {
steps {
script {
try {
withCredentials([usernamePassword(credentialsId: 'dev-ocp-credentials', passwordVariable: 'DEV_OCP_PASSWD', usernameVariable: 'DEV_OCP_USER')]) {
echo "Using Application: ${appName}"
sh('oc login -u $DEV_OCP_USER -p $DEV_OCP_PASSWD ${DEV_API_SERVER} -n ${SIT_NAMESPACE} --insecure-skip-tls-verify=true')
sh "oc tag ${DEV_NAMESPACE}/${appName}:latest ${SIT_NAMESPACE}/${appName}:latest -n ${SIT_NAMESPACE}"
}
} catch(e) {
print e.getMessage()
error "${SIT_NAMESPACE} promote stage having some issue. Please check logs for more details."
}
}
}
}
stage('Start Build to SIT Namespace') {
steps {
script {
try {
timeout(time: 600, unit: 'SECONDS') {
withCredentials([usernamePassword(credentialsId: 'dev-ocp-credentials', passwordVariable: 'DEV_OCP_PASSWD', usernameVariable: 'DEV_OCP_USER')]) {
sh('oc login -u $DEV_OCP_USER -p $DEV_OCP_PASSWD ${DEV_API_SERVER} -n ${SIT_NAMESPACE} --insecure-skip-tls-verify=true')
dc = sh(script: 'oc get dc ${appName} >> /dev/null 2>&1 && echo "true" || echo "false"', returnStdout: true)
dc = dc.trim()
echo "Deployment Config contains: '${dc}'"
if('true' == dc) {
echo "Application already exist. Hence rolling out the latest updates on the same."
sh """
oc rollout resume dc ${appName} -n ${SIT_NAMESPACE}
oc rollout status dc ${appName} -n ${SIT_NAMESPACE} -w
oc rollout pause dc ${appName} -n ${SIT_NAMESPACE}
"""
echo "Application ${appName}:${env.BUILD_NUMBER} has been successfully deployed to ${SIT_NAMESPACE} namespace."
} else {
echo "Deploying the ${appName}:latest application binary to ${SIT_NAMESPACE} namespace"
sh """
oc new-app ${appName}:latest --as-deployment-config -n ${SIT_NAMESPACE}
oc rollout status dc ${appName} -n ${SIT_NAMESPACE} -w
oc rollout pause dc ${appName} -n ${SIT_NAMESPACE}
"""
echo "Application ${appName}:latest deployed successfully to ${SIT_NAMESPACE} namespace."
}
}
}
} catch(e) {
print e.getMessage()
error "${SIT_NAMESPACE} start build stage having some issue. Please check logs for more details."
}
}
}
}
}
}