Skip to content

Commit

Permalink
refactor script
Browse files Browse the repository at this point in the history
  • Loading branch information
pranavgore09 committed Feb 9, 2018
1 parent 0b23291 commit a869abe
Showing 1 changed file with 8 additions and 6 deletions.
14 changes: 8 additions & 6 deletions vars/deployPlannerSnapshot.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -20,22 +19,25 @@ 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'
error 'Change author is not a collaborator on the project, aborting build until we support the [test] comment'
}

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') {
Expand Down

0 comments on commit a869abe

Please sign in to comment.