-
Notifications
You must be signed in to change notification settings - Fork 248
/
Jenkinsfile.ext-icp
92 lines (81 loc) · 3.56 KB
/
Jenkinsfile.ext-icp
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
// Basic Pipeline
def clusterCredsID = env.CLUSTER_CREDENTIALS ?: "icp-credentials"
def registryUrl = env.REGISTRY_URL ?: "mycluster.icp:8500"
def userName = env.USERID ?: "anonymous"
def releaseName = "pbw-liberty-mariadb-" + userName
pipeline {
environment {
REGISTRY_URL = "${registryUrl}"
MAJOR_PREFIX = "1.0.0"
RELEASE_NAME = "pbw-liberty-mariadb-${userName}"
REGISTRY_NS = "${DEPLOYMENT_NS}"
}
tools {
maven 'Apache Maven 3.0.5'
jdk 'IBM JDK 8.0'
}
agent { label 's390x' }
stages {
stage ('Initialize') {
steps {
sh '''
#!/bin/bash
echo "REGISTRY_URL = ${REGISTRY_URL}"
echo "DEPLOYMENT_NS = ${DEPLOYMENT_NS}"
echo "USERID = ${USERID}"
echo "RELEASE_NAME = ${RELEASE_NAME}"
'''
}
}
stage('Build application ear file') {
steps {
checkout scm
sh 'mvn clean package -DuserName=${USERID}'
}
}
stage('Build Docker Image') {
steps {
script {
echo "docker build -t ${REGISTRY_URL}/${REGISTRY_NS}/pbw-mariadb-web:${MAJOR_PREFIX}.${BUILD_NUMBER} ."
sh 'sudo docker build -t ${REGISTRY_URL}/${REGISTRY_NS}/pbw-mariadb-web:${MAJOR_PREFIX}.${BUILD_NUMBER} .'
}
}
}
stage('Push Docker Image to Registry') {
steps {
withCredentials([usernamePassword(credentialsId: clusterCredsID,
usernameVariable: 'USERNAME',
passwordVariable: 'PASSWORD')]) {
sh """
#!/bin/bash
sudo docker login -u ${USERNAME} -p ${PASSWORD} ${env.REGISTRY_URL}
sudo docker push ${env.REGISTRY_URL}/${env.REGISTRY_NS}/pbw-mariadb-web:${env.MAJOR_PREFIX}.${env.BUILD_NUMBER}
"""
}
}
}
stage('Deploy new Docker Image') {
steps {
echo 'Deploying....'
withCredentials([usernamePassword(credentialsId: clusterCredsID,
usernameVariable: 'USERNAME',
passwordVariable: 'PASSWORD')]) {
sh """#!/bin/bash
cloudctl login -u ${USERNAME} -p ${PASSWORD} -n ${env.DEPLOYMENT_NS} -a ${env.CLUSTER_URL}
DEPLOYMENT=`kubectl --namespace=${env.DEPLOYMENT_NS} get deployments -l app=pbw-liberty-mariadb,component=web-app,release=${env.RELEASE_NAME} --no-headers -o name`
if [ -z "\$DEPLOYMENT" ]; then
echo "FATAL ERROR: Deployment not found, exiting pipeline"
exit 22
else
echo "Existing deployment found, updating to point to image just created "
fi
kubectl --namespace=${env.DEPLOYMENT_NS} get \${DEPLOYMENT} --no-headers -o custom-columns=":metadata.name"
# Update Deployment
kubectl --namespace=${env.DEPLOYMENT_NS} set image \${DEPLOYMENT} ${env.RELEASE_NAME}-liberty=${env.REGISTRY_URL}/${env.REGISTRY_NS}/pbw-mariadb-web:${env.MAJOR_PREFIX}.${env.BUILD_NUMBER}
kubectl --namespace=${env.DEPLOYMENT_NS} rollout status \${DEPLOYMENT}
"""
}
}
}
}
}