Skip to content

Instantly share code, notes, and snippets.

@jovemfelix
Created October 23, 2020 19:50
Show Gist options
  • Select an option

  • Save jovemfelix/95b49e33a93b7d6ee5680d9a7e74bfe0 to your computer and use it in GitHub Desktop.

Select an option

Save jovemfelix/95b49e33a93b7d6ee5680d9a7e74bfe0 to your computer and use it in GitHub Desktop.
Openshift using jenkins pipeline -create or apply YML
/**
* @param args.FOLDER_YML
* @param args.OCP_KIND < configmap, secret >
* @return
*/
def manageYML(Map args) {
def configMapList = findFiles(glob: "${args.FOLDER_YML}")
echos "[${args.OCP_KIND}][found]: ${configMapList}"
configMapList.each { f ->
def strings = "${f}".split('/')
def filename = strings[strings.length - 1]
def fileNameWithoutExtension = filename.take(filename.lastIndexOf('.'))
if (openshift.selector(args.OCP_KIND, "${fileNameWithoutExtension}").exists()) {
echos "[${args.OCP_KIND}][update]: ${fileNameWithoutExtension}"
echos "[${args.OCP_KIND}][cat]: ${fileNameWithoutExtension}"
sh returnStdout: true, script: "cat ${f}"
openshift.apply('-f', "${f}")
} else {
echos "[${args.OCP_KIND}][create]: ${fileNameWithoutExtension}"
openshift.create('-f', "${f}", '--save-config', '--validate')
}
}
}
////
manageYML([
OCP_KIND : 'configmap',
FOLDER_YML: "${args.APP_DEFAULT_NAME}/${args.APP_AMBIENTE}/configmap/*.yml"
])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment