-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathJenkinsfile
100 lines (98 loc) · 3.64 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
95
96
97
98
99
100
#!bash
pipeline{
agent{
label 'docker'
}
environment {
appName = "sample-app"
appVersion = "0.0.1-SNAPSHOT"
buildconf = "false"
DEV_API_SERVER = "https://api.cluster-lb0d19.lb0d19.example.opentlc.com:6443"
DEV_NAMESPACE = "dev"
WORKSPACE = pwd()
templatePath = "${WORKSPACE}/config/template.json"
mvnCmd = "mvn -s ${WORKSPACE}/config/settings.xml"
}
stages {
stage('Parent Build'){
steps {
sh "mkdir -p /tmp/common-lib"
dir("/tmp/common-lib") {
git branch: 'main',
//credentialsId: 'git-credential',
url: 'https://github.com/vikassharma437/common-lib.git'
sh "${mvnCmd} clean deploy -DskipTests=true -Dversion=${env.BUILD_NUMBER}"
}
}
}
stage('Application Code Compile'){
steps{
//sleep time: 12000, unit: 'SECONDS'
sh "${mvnCmd} clean compile"
}
}
stage('Execute JUnit Test Cases'){
steps{
sh "${mvnCmd} package -Dversion=${env.BUILD_NUMBER}"
junit "target/surefire-reports/*.xml"
}
}
stage("Upload Artifact to Nexus") {
steps {
sh "${mvnCmd} deploy -DskipTests=true -Dversion=${env.BUILD_NUMBER}"
}
}
stage('Deploy Template in DEV Namespace') {
steps{
script {
try {
withCredentials([usernamePassword(credentialsId: 'dev-ocp-credentials', passwordVariable: 'DEV_OCP_PASSWD', usernameVariable: 'DEV_OCP_USER')]) {
echo "Using AppName: ${appName}"
sh('oc login -u $DEV_OCP_USER -p $DEV_OCP_PASSWD ${DEV_API_SERVER} -n ${DEV_NAMESPACE} --insecure-skip-tls-verify=true')
buildconf = sh(script: 'oc get bc ${appName} >> /dev/null 2>&1 && echo "true" || echo "false"', returnStdout: true)
buildconf = buildconf.trim()
echo "BuildConfig status contains: '${buildconf}'"
if(buildconf == 'false') {
sh "oc new-app ${templatePath} -n ${DEV_NAMESPACE} -p PROJECT=${DEV_NAMESPACE} -p APP_NAME=${appName}"
} else {
echo "Template is already exist. Hence, skipping this stage."
}
}
} catch(e) {
print e.getMessage()
error "${DEV_NAMESPACE} stage having some issue so this stage can be ignored. Please check logs for more details."
}
}
}
}
//Image Deployment
stage('Deploy Image Build to Dev Namespace') {
steps {
script {
try {
timeout(time: 180, 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 ${DEV_NAMESPACE} --insecure-skip-tls-verify=true')
sh "oc start-build ${appName} --from-file=target/${appName}-${appVersion}.jar --wait=true"
echo "Build ${appName} deployed successfully in ${DEV_NAMESPACE} namespace"
}
}
} catch(e) {
print e.getMessage()
error "Build not successful"
}
}
}
}
stage('Tag Image in Development Project') {
steps {
script {
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 ${DEV_NAMESPACE} --insecure-skip-tls-verify=true')
sh "oc tag ${DEV_NAMESPACE}/${appName}:latest ${DEV_NAMESPACE}/${appName}:${env.BUILD_NUMBER} -n ${DEV_NAMESPACE}"
}
}
}
}
}
}