From ce4ca1300d17bc0287ea904222698ce8881c826b Mon Sep 17 00:00:00 2001 From: Ovidio Mallo Date: Fri, 16 Dec 2016 11:34:37 +0100 Subject: [PATCH] Use the ocutil shared library --- deployment/pipeline.groovy | 74 +------------------------------------- 1 file changed, 1 insertion(+), 73 deletions(-) diff --git a/deployment/pipeline.groovy b/deployment/pipeline.groovy index c38f56d..a9c2a89 100644 --- a/deployment/pipeline.groovy +++ b/deployment/pipeline.groovy @@ -1,76 +1,4 @@ -import org.yaml.snakeyaml.Yaml - -def getOcCmd() { - return "oc --token=`cat /var/run/secrets/kubernetes.io/serviceaccount/token` --server=https://openshift.default.svc.cluster.local --certificate-authority=/run/secrets/kubernetes.io/serviceaccount/ca.crt" -} - -def getReplicas(namespace, name) { - def ocCmd = getOcCmd() - return sh(script: "${ocCmd} get dc ${name} --template='{{ .spec.replicas }}' -n ${namespace} || true", returnStdout: true).trim() -} - -@NonCPS -def parseYaml(content) { - return new Yaml().load(content) -} - -@NonCPS -def ocTemplateParametersAsCommandLineOpt(parameters) { - parameters.collect { parameter -> "-v ${parameter}" }.join(" ") -} - -def ocApplyTemplate(namespace, config) { - ocApplyTemplate(namespace, config.manifest, config.parameters) -} - -def ocApplyTemplate(namespace, manifest, parameters) { - def ocCmd = getOcCmd() - def parametersOpt = ocTemplateParametersAsCommandLineOpt(parameters) - sh "${ocCmd} process -f ${manifest} ${parametersOpt} -n ${namespace} | ${ocCmd} apply -f - -n ${namespace}" -} - -def ocDelete(namespace, target) { - def ocCmd = getOcCmd() - sh "${ocCmd} delete ${target.type}/${target.name} -n ${namespace} || true" -} - -def ocBuild(namespace, name, config) { - def ocCmd = getOcCmd() - - for (def target : config.delete) { - ocDelete(namespace, target) - } - - for (def template : config.templates) { - ocApplyTemplate(namespace, template) - } - - sh "${ocCmd} start-build ${name} -w -n ${namespace}" -} - -def ocTag(isNamespace, isName, sourceTag, targetTag) { - sh "${ocCmd} tag ${isNamespace}/${isName}:${sourceTag} ${isNamespace}/${isName}:${targetTag}" -} - -def ocDeploy(namespace, name, config) { - def replicas = getReplicas(namespace, name) - - for (def target : config.delete) { - ocDelete(namespace, target) - } - - for (def template : config.templates) { - def manifest = template.manifest - def parameters = template.parameters.clone() - if (replicas) { - parameters["REPLICAS"] = replicas - } - ocApplyTemplate(namespace, manifest, parameters) - } - - sh "${ocCmd} rollout latest dc/${name} -n ${namespace}" - sh "${ocCmd} rollout status dc/${name} -n ${namespace}" -} +@Library('ocutil') _ node() { stage("Checkout") {