From a869abe28c29d673c1ff7a158b265314a7f963a0 Mon Sep 17 00:00:00 2001 From: Pranav Gore Date: Fri, 9 Feb 2018 13:40:10 +0530 Subject: [PATCH] refactor script --- vars/deployPlannerSnapshot.groovy | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/vars/deployPlannerSnapshot.groovy b/vars/deployPlannerSnapshot.groovy index 8cdd8cdd..f898ee78 100644 --- a/vars/deployPlannerSnapshot.groovy +++ b/vars/deployPlannerSnapshot.groovy @@ -10,7 +10,6 @@ def call(body) { body() def yaml - def openShiftProject = config.openShiftProject def openShiftTemplate = config.openShiftTemplate def originalImageName = config.originalImageName def newImageName = config.newImageName @@ -20,8 +19,8 @@ def call(body) { def flow = new io.fabric8.Fabric8Commands() def utils = new io.fabric8.Utils() + def openShiftProject = config.openShiftProject + '-' + utils.getRepoName() - openShiftProject = openShiftProject + '-' + utils.getRepoName() container('clients') { if (!flow.isAuthorCollaborator("", project)){ currentBuild.result = 'ABORTED' @@ -29,13 +28,16 @@ def call(body) { } yaml = flow.getUrlAsString(openShiftTemplate) - yaml = Pattern.compile("- image: ${originalImageName}:(.*)").matcher(yaml).replaceFirst("- image: ${newImageName}") + def originalImage = "- image: ${originalImageName}:(.*)" + def newImage = "- image: ${newImageName}" + yaml = Pattern.compile(originalImage).matcher(yaml).replaceFirst(newImage) - if (!yaml.contains(newImageName)){ - error "original image ${originalImageName} not replaced with ${newImageName} in yaml: \n ${yaml}" + if (!yaml.contains(newImage)){ + error "original image ${originalImageName} not replaced with ${newImage} in yaml: \n ${yaml}" } } - // cant use writeFile as we have long filename errors + // cant use writeFile as we are facing following error + // Scripts not permitted to use staticMethod org.codehaus.groovy.runtime.DefaultGroovyMethods sh "echo '${yaml}' > snapshot.yml" container('clients') {