Groovy web console

subscribe to the feed Subscribe
to this
site

vf-image-promotion

Published 1 month ago by Anonymous
Actions Execute script  ▶ Edit in console Back to console Show/hide line numbers View recent scripts
          
def imageName = "dev.2-naap-cpe-management-0.0.3-g839b07"

def validationRegex = /^(ga|rc(\.([0-9]{1,3})){0,1}|dev(\.([0-9]{1,3})){0,1}|test(\.([0-9]{1,3})){0,1}){1}(-([a-z|-]{3,40}[a-z]{0,1})){0,1}-([0-9]{1,2}\.[0-9]{1,2}\.[0-9]{1,3})(-([a-z0-9]{7})){0,1}$/          

          // def match = params.image_name =~ imageRegex
            def match = imageName =~ validationRegex
          if (!match) {
            error("Invalid image name, does not match CaaS specification")
          }
/*
          print match[0][0]
          print match[0][1]
          print match[0][2]
          print match[0][3]
          print match[0][4]
          print match[0][5]
          def imageEnv = match[0][1]
          def buildNr = match[0][2]
          // dev.2-naap-cpe-management-0.0.3-g839b07
          // NEW_TAG = params.env + buildNr + 
          // NEW_TAG = params.image_name + "-" + params.env
        print imageEnv
        print buildNr
*/
// from dev to test, we can just replace the prefix

        def newImageName = imageName.replaceFirst("dev", "test")
        print newImageName