Skip to content
This repository was archived by the owner on Jun 25, 2025. It is now read-only.

Commit 0490a4d

Browse files
committed
Deploy plannerUI snapshot
Added new groovy script for building and deploying plannerUI standalone snapshot in CI.
1 parent 4b899c6 commit 0490a4d

File tree

1 file changed

+65
-0
lines changed

1 file changed

+65
-0
lines changed

vars/deployPlannerSnapshot.groovy

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
#!/usr/bin/groovy
2+
3+
import java.util.regex.Pattern
4+
5+
def call(body) {
6+
// evaluate the body block, and collect configuration into the object
7+
def config = [:]
8+
body.resolveStrategy = Closure.DELEGATE_FIRST
9+
body.delegate = config
10+
body()
11+
12+
def openShiftTemplate = config.openShiftTemplate
13+
def originalImageName = config.originalImageName
14+
def newImageName = config.newImageName
15+
def deploymentName = config.githubRepo
16+
def providerLabel = config.providerLabel ?: 'fabric8'
17+
def project = config.githubProject
18+
19+
def flow = new io.fabric8.Fabric8Commands()
20+
def utils = new io.fabric8.Utils()
21+
def openShiftProject = config.openShiftProject + '-' + utils.getRepoName()
22+
23+
if (!flow.isAuthorCollaborator("", project)){
24+
currentBuild.result = 'ABORTED'
25+
error 'Change author is not a collaborator on the project, aborting build until we support the [test] comment'
26+
}
27+
def yaml = flow.getUrlAsString(openShiftTemplate)
28+
def originalImage = "- image: ${originalImageName}:(.*)"
29+
def newImage = "- image: ${newImageName}"
30+
def compiledYaml = Pattern.compile(originalImage).matcher(yaml).replaceFirst(newImage)
31+
32+
if (!compiledYaml.contains(newImage)){
33+
error "original image ${originalImage} not replaced with ${newImage} in yaml: \n ${compiledYaml}"
34+
}
35+
// cant use writeFile as we are facing following error
36+
// Scripts not permitted to use staticMethod org.codehaus.groovy.runtime.DefaultGroovyMethods
37+
sh "echo '${compiledYaml}' > snapshot.yml"
38+
39+
container('clients') {
40+
try {
41+
sh "oc get project ${openShiftProject} | grep Active"
42+
} catch (err) {
43+
echo "${err}"
44+
sh "oc new-project ${openShiftProject}"
45+
}
46+
47+
sh "oc process -n ${openShiftProject} -f ./snapshot.yml | oc apply -n ${openShiftProject} -f -"
48+
49+
sleep 10
50+
// ok bad bad but there's a delay between DC's being applied and new pods being started. lets find a better way to do this looking at teh new DC perhaps?
51+
52+
waitUntil {
53+
// wait until the pods are running has been deleted
54+
try {
55+
sh "oc get pod -l app=${deploymentName},provider=${providerLabel} -n ${openShiftProject} | grep Running"
56+
echo "${deploymentName} pod is running"
57+
return true
58+
} catch (err) {
59+
echo "waiting for ${deploymentName} to be ready..."
60+
return false
61+
}
62+
}
63+
return sh(script: "oc get route ${deploymentName} -o jsonpath=\"{.spec.host}\" -n ${openShiftProject}", returnStdout: true).toString().trim()
64+
}
65+
}

0 commit comments

Comments
 (0)