From a77231a31457da3bd26a2f4de373a2f9e29518b6 Mon Sep 17 00:00:00 2001 From: Student User Date: Fri, 9 Jul 2021 07:41:58 -0400 Subject: [PATCH] Completed Jenkinsfile for books microservice --- books/jenkins/Jenkinsfile | 39 ++++++++++++++++++++++++++++++--------- 1 file changed, 30 insertions(+), 9 deletions(-) diff --git a/books/jenkins/Jenkinsfile b/books/jenkins/Jenkinsfile index c862086..a3acfcb 100644 --- a/books/jenkins/Jenkinsfile +++ b/books/jenkins/Jenkinsfile @@ -5,16 +5,19 @@ pipeline { } agent { node { - //TODO: Add label for Node.js jenkins agent + label 'nodejs' } } environment { //TODO: Edit these vars as per your env - DEV_PROJECT = "youruser-books-dev" - STAGE_PROJECT = "youruser-books-stage" - APP_GIT_URL = "https://github.com/youruser/DO288-apps" - NEXUS_SERVER = "http://nexus-common.apps.cluster.domain.example.com/repository/nodejs" + DEV_PROJECT = "zqjsga-books-dev" + STAGE_PROJECT = "zqjsga-books-stage" + APP_GIT_URL = "https://github.com/shautvast/DO288-apps" + NEXUS_SERVER = "http://nexus-common.apps.eu45.prod.nextcle.com" +#it says replace the whole value +# NEXUS_SERVER = "http://nexus-common.apps.cluster.domain.example.com/repository/nodejs" + // DO NOT CHANGE THE GLOBAL VARS BELOW THIS LINE APP_NAME = "books" @@ -58,7 +61,13 @@ pipeline { ''' echo '### Creating a new app in DEV env ###' - //TODO: Create a new app and expose the service + sh ''' + oc project ${DEV_PROJECT} + oc new-app --as-deployment-config --name books nodejs:12~${APP_GIT_URL}\ + --build-env npm_config_registry=${NEXUS_SERVER} --context-dir ${APP_NAME} + + oc expose svc/${APP_NAME} + ''' } } @@ -99,7 +108,10 @@ pipeline { timeout(time: 60, unit: 'MINUTES') { input message: "Promote to Staging?" } - //TODO: Tag the books:latest image stream as books:stage + script{ + openshift.withCluster() { + openshift.tag("${DEV_PROJECT}/books/latest", "${STAGE_PROJECT}/books:stage") + } } } @@ -113,7 +125,11 @@ pipeline { ''' echo '### Creating a new app in Staging ###' - //TODO: Create a new app in stage using the books:stage image stream and expose the service + sh ''' + oc project ${STAGE_PROJECT} + oc new-app --as-depoyment-config --name books -i books:stage + oc expose svc ${APP_NAME} + ''' } } @@ -125,7 +141,12 @@ pipeline { routeHost = readFile('routehost').trim() openshift.withCluster() { - //TODO: Watch deployment until pod is in 'Running' state + openshift.withProject( "${STAGE_PROJECT}" ) { + def deployment = openshift.selector("dc", "${APP_NAME}").rollout() + openshift.selector("dc", "$APP_NAME").related('pods').untilEach(1){ + return (it.object().status.phase == "Running") + } + } echo "Deployment to Staging env is complete. Access the app at the URL http://${routeHost}." }