-
Notifications
You must be signed in to change notification settings - Fork 0
/
Jenkinsfile
62 lines (62 loc) · 3.44 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
node('maven') {
// Start session with the service account jenkins which is the one configured by default for this builder
openshift.withCluster() {
stage('Building project') {
// All commands in this closure will be perform in the project 'tasks-test'
openshift.withProject( 'tasks-test' ) {
// Get the build config for the application
def bc = openshift.selector('bc', 'tasks')
// Trigger the build, if it success, the new image will be pushed to the imagestream and tagged as 'latest'
def buildInfo = bc.startBuild()
// Follow the output of the build process until it finishes
buildInfo.logs('-f')
}
}
stage('Deploying to TEST') {
// All commands in this closure will be perform in the project 'tasks-test'
openshift.withProject( 'tasks-test' ) {
// Let's make the image ready to deploy as the new application in TEST
openshift.tag('tasks:latest', 'tasks:test')
// Get the deployment config for the application
def dc = openshift.selector('dc', 'tasks')
// Since the deployment config is already pointing to a the tag 'test', deploy the new version without changing anything
dc.rollout().latest()
// Get the information of the replica controller created for the last deployment
def latestDeploymentVersion = dc.object().status.latestVersion
// Get the replica controller object
def rc = openshift.selector('rc', "tasks-${latestDeploymentVersion}")
// Loop until its content returns 'true' at least once
rc.untilEach(1){
// Refresh the information of the replica controller
def rcMap = it.object()
// If the number of replicas already started matches the desired number, return 'true'
return (rcMap.status.replicas.equals(rcMap.status.readyReplicas))
}
}
}
stage('Promoting to LIVE') {
// Wait until the test deployment has been validated before continueing
input "Promote new version to LIVE?"
// All commands in this closure will be perform in the project 'tasks-live'
openshift.withProject( 'tasks-live' ) {
// There is no declarative method to import the new image into the live project. We are referring the image locally so if the test project is eventually deleted all images will remain in the live project.
openshift.raw( 'import-image', 'tasks:live', "--from='docker-registry.default.svc:5000/tasks-test/tasks:latest'", '--confirm', "--reference-policy='local'" )
// Get the deployment config for the application
def dc = openshift.selector('dc', 'tasks')
// Since the deployment config is already pointing to a the tag 'live', deploy the new version without changing anything
dc.rollout().latest()
// Get the information of the replica controller created for the last deployment
def latestDeploymentVersion = dc.object().status.latestVersion
// Get the replica controller object
def rc = openshift.selector('rc', "tasks-${latestDeploymentVersion}")
// Loop until its content returns 'true' at least once
rc.untilEach(1){
// Refresh the information of the replica controller
def rcMap = it.object()
// If the number of replicas already started matches the desired number, return 'true'
return (rcMap.status.replicas.equals(rcMap.status.readyReplicas))
}
}
}
}
}