-
Notifications
You must be signed in to change notification settings - Fork 5
/
Jenkinsfile
62 lines (56 loc) · 2.11 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
#!groovy
pipeline {
agent any
stages {
stage('Build') {
steps {
script {
sh(returnStdout: true, script: 'docker pull jboss/keycloak:latest')
image = docker.build('keycloak')
}
}
}
stage('Publish') {
when {
expression {
// If the build is successful and we're not building a PR, publish the build to Nexus
return !env.CHANGE_ID && (currentBuild.result == null || currentBuild.result == 'SUCCESS')
}
}
steps {
script {
COMMIT_HASH = sh(returnStdout: true, script: 'git rev-parse --short HEAD').trim()
docker.withRegistry('https://registry.csh.rit.edu', 'nexus-jenkins') {
if (env.BRANCH_NAME == 'master') {
image.push('latest')
} else {
image.push(env.BRANCH_NAME)
}
image.push(COMMIT_HASH)
}
}
}
}
stage('Deploy') {
when {
expression {
// If we're not building a PR, the build is successful, and we're on the master branch, deploy to OpenShift
return !env.CHANGE_ID && (env.BRANCH_NAME == 'master') &&
(currentBuild.result == null || currentBuild.result == 'SUCCESS')
}
}
steps {
script {
openshift.withCluster('csh') {
openshift.withProject('keycloak') {
openshift.doAs('os-sa-keycloak') {
openshift.tag("docker.csh.rit.edu/keycloak:${COMMIT_HASH}", 'keycloak/keycloak:latest')
openshift.selector('dc', [app: 'keycloak']).deploy()
}
}
}
}
}
}
}
}