ruby-ex/deployment/pipeline.groovy

46 lines
1.9 KiB
Groovy
Raw Normal View History

2016-12-07 23:28:53 +00:00
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"
}
2016-12-06 09:10:10 +00:00
2016-12-07 23:26:40 +00:00
def getReplicasOpt(deploymentConfig, project) {
2016-12-07 23:28:53 +00:00
def ocCmd = getOcCmd()
2016-12-08 16:39:48 +00:00
def replicas = sh(script: "${ocCmd} get dc ${deploymentConfig} --template='{{ .spec.replicas }}' -n ${project} || true", returnStdout: true).trim()
2016-12-07 23:26:40 +00:00
return replicas ? "-v REPLICAS=${replicas}" : ""
}
2016-12-07 23:24:05 +00:00
2016-12-07 23:26:40 +00:00
node() {
2016-12-07 23:28:53 +00:00
def ocCmd = getOcCmd()
2016-12-07 22:25:57 +00:00
def buildConfigFile = "deployment/config/build.yaml"
def appConfigFile = "deployment/config/app.yaml"
2016-12-05 14:32:22 +00:00
stage('Build') {
2016-12-07 22:21:17 +00:00
git "https://github.com/omallo/ruby-ex.git"
2016-12-07 22:14:47 +00:00
sh "${ocCmd} process -f ${buildConfigFile} -n rubex-dev | ${ocCmd} apply -f - -n rubex-dev"
2016-12-06 09:10:10 +00:00
sh "${ocCmd} start-build frontend -w -n rubex-dev"
2016-12-05 14:32:22 +00:00
}
stage('Deploy to DEV') {
2016-12-07 23:24:05 +00:00
def replicasOpt = getReplicasOpt("frontend", "rubex-dev")
sh "${ocCmd} process -f ${appConfigFile} -v ENV=dev ${replicasOpt} -n rubex-dev | ${ocCmd} apply -f - -n rubex-dev"
2016-12-06 09:10:10 +00:00
sh "${ocCmd} tag rubex-dev/frontend:latest rubex-dev/frontend:dev"
sh "${ocCmd} rollout latest dc/frontend -n rubex-dev"
sh "${ocCmd} rollout status dc/frontend -n rubex-dev"
2016-12-05 14:32:22 +00:00
}
def isPromoteToTest = false
stage('Promote to TEST?') {
isPromoteToTest = input(message: 'Promotion', parameters: [booleanParam(defaultValue: false, name: 'Promote to TEST?')])
}
if (isPromoteToTest) {
stage('Deploy to TEST') {
2016-12-07 23:24:05 +00:00
def replicasOpt = getReplicasOpt("frontend", "rubex-test")
sh "${ocCmd} process -f ${appConfigFile} -v ENV=test ${replicasOpt} -n rubex-test | ${ocCmd} apply -f - -n rubex-test"
2016-12-06 09:10:10 +00:00
sh "${ocCmd} tag rubex-dev/frontend:dev rubex-dev/frontend:test"
sh "${ocCmd} rollout latest dc/frontend -n rubex-test"
sh "${ocCmd} rollout status dc/frontend -n rubex-test"
2016-12-05 14:32:22 +00:00
}
}
}