From 02a9f7e042fb1693ccb24ea2ca3060df715ddfc4 Mon Sep 17 00:00:00 2001 From: harshavardhanc Date: Mon, 14 Dec 2020 17:58:38 +0530 Subject: [PATCH 1/6] auto build pipeline --- bot/auto_build_deploy | 65 ++++++++++++++++++++++++++++++++++++++++ router/auto_build_deploy | 65 ++++++++++++++++++++++++++++++++++++++++ 2 files changed, 130 insertions(+) create mode 100644 bot/auto_build_deploy create mode 100644 router/auto_build_deploy diff --git a/bot/auto_build_deploy b/bot/auto_build_deploy new file mode 100644 index 0000000..1ee5496 --- /dev/null +++ b/bot/auto_build_deploy @@ -0,0 +1,65 @@ +@Library('deploy-conf') _ +node('build-slave') { + try { + String ANSI_GREEN = "\u001B[32m" + String ANSI_NORMAL = "\u001B[0m" + String ANSI_BOLD = "\u001B[1m" + String ANSI_RED = "\u001B[31m" + String ANSI_YELLOW = "\u001B[33m" + + ansiColor('xterm') { + withEnv(["JAVA_HOME=${JAVA11_HOME}"]) { + stage('Checkout') { + tag_name = env.JOB_NAME.split("/")[ - 1] + pre_checks() + if (!env.hub_org) { + println(ANSI_BOLD + ANSI_RED + "Uh Oh! Please set a Jenkins environment variable named hub_org with value as registery/sunbidrded" + ANSI_NORMAL) + error 'Please resolve the errors and rerun..' + } else println(ANSI_BOLD + ANSI_GREEN + "Found environment variable named hub_org with value as: " + hub_org + ANSI_NORMAL) + } + cleanWs() + def scmVars = checkout scm + checkout scm: [$class: 'GitSCM', branches: [[name: "refs/tags/$tag_name"]], userRemoteConfigs: [[url: scmVars.GIT_URL]]] + build_tag = tag_name + "_" + env.BUILD_NUMBER + commit_hash = sh(script: 'git rev-parse --short HEAD', returnStdout: true).trim() + public_repo_commit_hash = branch_name + "_" + commit_hash + artifact_version = tag_name + "_" + commit_hash + echo "build_tag: " + build_tag + echo "public_repo_commit_hash: " + public_repo_commit_hash + + dir('bot_repo') { + def scmVarsPrivate = checkout scm + checkout scm: ([$class: 'GitSCM', branches: [[name: "refs/heads/master"]], doGenerateSubmoduleConfigurations: false, extensions: [[$class: 'CloneOption', depth: 0, noTags: false, reference: '', shallow: true]], submoduleCfg: [], userRemoteConfigs: [[credentialsId: 'private_repo_credentials', url: "https://github.com/DIKSHA-NCTE/Diksha-Bot.git"]]]) + private_repo_commit_hash = sh(script: 'git rev-parse --short HEAD', returnStdout: true).trim() + } + + stage('Build') { + env.NODE_ENV = "build" + print "Environment will be : ${env.NODE_ENV}" + build_tag = public_repo_commit_hash + "_" + private_repo_commit_hash + "_" + env.BUILD_NUMBER + "_bot" + sh('cp -r bot_repo/* .') + dir('bot') { + sh('chmod 777 build.sh') + sh("./build.sh ${build_tag} ${env.NODE_NAME} ${hub_org}") + } + + } + + // stage ArchiveArtifacts + archiveArtifacts "metadata.json" + currentBuild.description = "${build_tag}" + + } + currentBuild.result = "SUCCESS" + slack_notify(currentBuild.result, tag_name) + email_notify() + auto_build_deploy() + } + } + catch(err) { + currentBuild.result = "FAILURE" + slack_notify(currentBuild.result, tag_name) + email_notify() + throw err + } +} diff --git a/router/auto_build_deploy b/router/auto_build_deploy new file mode 100644 index 0000000..f897ca7 --- /dev/null +++ b/router/auto_build_deploy @@ -0,0 +1,65 @@ +@Library('deploy-conf') _ +node('build-slave') { + try { + String ANSI_GREEN = "\u001B[32m" + String ANSI_NORMAL = "\u001B[0m" + String ANSI_BOLD = "\u001B[1m" + String ANSI_RED = "\u001B[31m" + String ANSI_YELLOW = "\u001B[33m" + + ansiColor('xterm') { + withEnv(["JAVA_HOME=${JAVA11_HOME}"]) { + stage('Checkout') { + tag_name = env.JOB_NAME.split("/")[ - 1] + pre_checks() + if (!env.hub_org) { + println(ANSI_BOLD + ANSI_RED + "Uh Oh! Please set a Jenkins environment variable named hub_org with value as registery/sunbidrded" + ANSI_NORMAL) + error 'Please resolve the errors and rerun..' + } else println(ANSI_BOLD + ANSI_GREEN + "Found environment variable named hub_org with value as: " + hub_org + ANSI_NORMAL) + } + cleanWs() + def scmVars = checkout scm + checkout scm: [$class: 'GitSCM', branches: [[name: "refs/tags/$tag_name"]], userRemoteConfigs: [[url: scmVars.GIT_URL]]] + build_tag = tag_name + "_" + env.BUILD_NUMBER + commit_hash = sh(script: 'git rev-parse --short HEAD', returnStdout: true).trim() + public_repo_commit_hash = branch_name + "_" + commit_hash + artifact_version = tag_name + "_" + commit_hash + echo "build_tag: " + build_tag + echo "public_repo_commit_hash: " + public_repo_commit_hash + + dir('bot_repo') { + def scmVarsPrivate = checkout scm + checkout scm: ([$class: 'GitSCM', branches: [[name: "refs/heads/master"]], doGenerateSubmoduleConfigurations: false, extensions: [[$class: 'CloneOption', depth: 0, noTags: false, reference: '', shallow: true]], submoduleCfg: [], userRemoteConfigs: [[credentialsId: 'private_repo_credentials', url: "https://github.com/DIKSHA-NCTE/Diksha-Bot.git"]]]) + private_repo_commit_hash = sh(script: 'git rev-parse --short HEAD', returnStdout: true).trim() + } + + stage('Build') { + env.NODE_ENV = "build" + print "Environment will be : ${env.NODE_ENV}" + build_tag = public_repo_commit_hash + "_" + private_repo_commit_hash + "_" + env.BUILD_NUMBER + "_router" + sh('cp -r bot_repo/* .') + dir('router') { + sh('chmod 777 build.sh') + sh("./build.sh ${build_tag} ${env.NODE_NAME} ${hub_org}") + } + + } + + // stage ArchiveArtifacts + archiveArtifacts "metadata.json" + currentBuild.description = "${build_tag}" + + } + currentBuild.result = "SUCCESS" + slack_notify(currentBuild.result, tag_name) + email_notify() + auto_build_deploy() + } + } + catch(err) { + currentBuild.result = "FAILURE" + slack_notify(currentBuild.result, tag_name) + email_notify() + throw err + } +} From a85f13e57da02b527d9c2d1f829f9495f27f67d4 Mon Sep 17 00:00:00 2001 From: G33tha Date: Wed, 3 Feb 2021 15:49:56 +0530 Subject: [PATCH 2/6] Update Jenkinsfile --- bot/Jenkinsfile | 35 +++++++++++++++++++++-------------- 1 file changed, 21 insertions(+), 14 deletions(-) diff --git a/bot/Jenkinsfile b/bot/Jenkinsfile index f176aa9..8c48c34 100644 --- a/bot/Jenkinsfile +++ b/bot/Jenkinsfile @@ -29,26 +29,33 @@ node('build-slave') { println(ANSI_BOLD + ANSI_YELLOW + "github_release_tag specified, building from github_release_tag: " + params.github_release_tag + ANSI_NORMAL) } echo "public_repo_commit_hash: " + public_repo_commit_hash - bot_repo_url = params.diksha_bot_repo - dir('bot_repo') { - if (params.diksha_bot_tag == "") { - def scmVars = checkout scm - checkout scm: ([$class: 'GitSCM', branches: [[name: "refs/heads/master"]], doGenerateSubmoduleConfigurations: false, extensions: [[$class: 'CloneOption', depth: 0, noTags: false, reference: '', shallow: true]], submoduleCfg: [], userRemoteConfigs: [[credentialsId: 'private_repo_credentials', url: "$bot_repo_url"]]]) - private_repo_commit_hash = sh(script: 'git rev-parse --short HEAD', returnStdout: true).trim() - } - else { - def scmVars = checkout scm - checkout scm: ([$class: 'GitSCM', branches: [[name: "refs/tags/params.diksha_bot_tag"]], doGenerateSubmoduleConfigurations: false, extensions: [[$class: 'CloneOption', depth: 0, noTags: false, reference: '', shallow: true]], submoduleCfg: [], userRemoteConfigs: [[credentialsId: 'private_repo_credentials', url: "$bot_repo_url"]]]) - private_repo_commit_hash = params.diksha_bot_tag - } - } + bot_repo_url = params.private_bot_repo + + if (params.private_bot_repo && params.private_bot_tag) { + dir('bot_repo') { + if (params.private_bot_tag == "") { + def scmVars = checkout scm + checkout scm: ([$class: 'GitSCM', branches: [[name: "refs/heads/master"]], doGenerateSubmoduleConfigurations: false, extensions: [[$class: 'CloneOption', depth: 0, noTags: false, reference: '', shallow: true]], submoduleCfg: [], userRemoteConfigs: [[credentialsId: 'private_repo_credentials', url: "$bot_repo_url"]]]) + private_repo_commit_hash = sh(script: 'git rev-parse --short HEAD', returnStdout: true).trim() + } + else { + def scmVars = checkout scm + checkout scm: ([$class: 'GitSCM', branches: [[name: "refs/tags/params.private_bot_tag"]], doGenerateSubmoduleConfigurations: false, extensions: [[$class: 'CloneOption', depth: 0, noTags: false, reference: '', shallow: true]], submoduleCfg: [], userRemoteConfigs: [[credentialsId: 'private_repo_credentials', url: "$bot_repo_url"]]]) + private_repo_commit_hash = params.private_bot_tag + } + } + + } + } stage('Build') { env.NODE_ENV = "build" print "Environment will be : ${env.NODE_ENV}" build_tag = public_repo_commit_hash + "_" + private_repo_commit_hash + "_" + env.BUILD_NUMBER + "_bot" - sh('cp -r bot_repo/* .') + if (params.private_bot_repo && params.private_bot_tag) { + sh('cp -r bot_repo/* .') + } dir('bot') { sh('chmod 777 build.sh') sh("./build.sh ${build_tag} ${env.NODE_NAME} ${hub_org}") From c11541e7134a4f10373a68dd95035f01690b7339 Mon Sep 17 00:00:00 2001 From: G33tha Date: Wed, 3 Feb 2021 16:21:20 +0530 Subject: [PATCH 3/6] Update Jenkinsfile --- bot/Jenkinsfile | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/bot/Jenkinsfile b/bot/Jenkinsfile index 8c48c34..57ee21a 100644 --- a/bot/Jenkinsfile +++ b/bot/Jenkinsfile @@ -31,7 +31,7 @@ node('build-slave') { echo "public_repo_commit_hash: " + public_repo_commit_hash bot_repo_url = params.private_bot_repo - if (params.private_bot_repo && params.private_bot_tag) { + if (params.private_bot_repo || params.private_bot_tag) { dir('bot_repo') { if (params.private_bot_tag == "") { def scmVars = checkout scm @@ -52,9 +52,10 @@ node('build-slave') { stage('Build') { env.NODE_ENV = "build" print "Environment will be : ${env.NODE_ENV}" - build_tag = public_repo_commit_hash + "_" + private_repo_commit_hash + "_" + env.BUILD_NUMBER + "_bot" + build_tag = public_repo_commit_hash + "_" + env.BUILD_NUMBER + "_bot" if (params.private_bot_repo && params.private_bot_tag) { sh('cp -r bot_repo/* .') + build_tag = public_repo_commit_hash + "_" + private_repo_commit_hash + "_" + env.BUILD_NUMBER + "_bot" } dir('bot') { sh('chmod 777 build.sh') From fc315a8db23d07893fe561b9f5a5af727a8a950a Mon Sep 17 00:00:00 2001 From: G33tha Date: Wed, 3 Feb 2021 18:26:16 +0530 Subject: [PATCH 4/6] Update Jenkinsfile --- router/Jenkinsfile | 22 +++++++++++++++------- 1 file changed, 15 insertions(+), 7 deletions(-) diff --git a/router/Jenkinsfile b/router/Jenkinsfile index a6ae9e2..a3c935b 100644 --- a/router/Jenkinsfile +++ b/router/Jenkinsfile @@ -30,26 +30,34 @@ node('build-slave') { } echo "public_repo_commit_hash: " + public_repo_commit_hash - bot_repo_url = params.diksha_bot_repo - dir('bot_repo') { - if (params.diksha_bot_tag == "") { + bot_repo_url = params.private_bot_repo + + if (params.private_bot_repo || params.private_bot_tag) { + dir('bot_repo') { + if (params.private_bot_tag == "") { def scmVars = checkout scm checkout scm: ([$class: 'GitSCM', branches: [[name: "refs/heads/master"]], doGenerateSubmoduleConfigurations: false, extensions: [[$class: 'CloneOption', depth: 0, noTags: false, reference: '', shallow: true]], submoduleCfg: [], userRemoteConfigs: [[credentialsId: 'private_repo_credentials', url: "$bot_repo_url"]]]) private_repo_commit_hash = sh(script: 'git rev-parse --short HEAD', returnStdout: true).trim() } else { def scmVars = checkout scm - checkout scm: ([$class: 'GitSCM', branches: [[name: "refs/tags/params.diksha_bot_tag"]], doGenerateSubmoduleConfigurations: false, extensions: [[$class: 'CloneOption', depth: 0, noTags: false, reference: '', shallow: true]], submoduleCfg: [], userRemoteConfigs: [[credentialsId: 'private_repo_credentials', url: "$bot_repo_url"]]]) - private_repo_commit_hash = params.diksha_bot_tag + checkout scm: ([$class: 'GitSCM', branches: [[name: "refs/tags/params.private_bot_tag"]], doGenerateSubmoduleConfigurations: false, extensions: [[$class: 'CloneOption', depth: 0, noTags: false, reference: '', shallow: true]], submoduleCfg: [], userRemoteConfigs: [[credentialsId: 'private_repo_credentials', url: "$bot_repo_url"]]]) + private_repo_commit_hash = params.private_bot_tag } } + + } } stage('Build') { env.NODE_ENV = "build" print "Environment will be : ${env.NODE_ENV}" - build_tag = public_repo_commit_hash + "_" + private_repo_commit_hash + "_" + env.BUILD_NUMBER + "_router" - sh('cp -r bot_repo/* .') + + build_tag = public_repo_commit_hash + "_" + env.BUILD_NUMBER + "_bot" + if (params.private_bot_repo && params.private_bot_tag) { + sh('cp -r bot_repo/* .') + build_tag = public_repo_commit_hash + "_" + private_repo_commit_hash + "_" + env.BUILD_NUMBER + "_bot" + } dir('router') { sh('chmod 777 build.sh') sh("./build.sh ${build_tag} ${env.NODE_NAME} ${hub_org}") From 6aeac23c34d0d9be6200a1a3acf64783f69f4f8e Mon Sep 17 00:00:00 2001 From: G33tha Date: Thu, 4 Feb 2021 13:35:41 +0530 Subject: [PATCH 5/6] Update Jenkinsfile --- bot/Jenkinsfile | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/bot/Jenkinsfile b/bot/Jenkinsfile index 57ee21a..0deb795 100644 --- a/bot/Jenkinsfile +++ b/bot/Jenkinsfile @@ -31,7 +31,7 @@ node('build-slave') { echo "public_repo_commit_hash: " + public_repo_commit_hash bot_repo_url = params.private_bot_repo - if (params.private_bot_repo || params.private_bot_tag) { + if (params.private_bot_repo) { dir('bot_repo') { if (params.private_bot_tag == "") { def scmVars = checkout scm @@ -53,7 +53,7 @@ node('build-slave') { env.NODE_ENV = "build" print "Environment will be : ${env.NODE_ENV}" build_tag = public_repo_commit_hash + "_" + env.BUILD_NUMBER + "_bot" - if (params.private_bot_repo && params.private_bot_tag) { + if (params.private_bot_repo) { sh('cp -r bot_repo/* .') build_tag = public_repo_commit_hash + "_" + private_repo_commit_hash + "_" + env.BUILD_NUMBER + "_bot" } From e32221683292c3d0d509b31fee80467fdac149ec Mon Sep 17 00:00:00 2001 From: G33tha Date: Thu, 4 Feb 2021 13:36:24 +0530 Subject: [PATCH 6/6] Update Jenkinsfile --- router/Jenkinsfile | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/router/Jenkinsfile b/router/Jenkinsfile index a3c935b..b1d16bf 100644 --- a/router/Jenkinsfile +++ b/router/Jenkinsfile @@ -32,7 +32,7 @@ node('build-slave') { echo "public_repo_commit_hash: " + public_repo_commit_hash bot_repo_url = params.private_bot_repo - if (params.private_bot_repo || params.private_bot_tag) { + if (params.private_bot_repo) { dir('bot_repo') { if (params.private_bot_tag == "") { def scmVars = checkout scm @@ -54,7 +54,7 @@ node('build-slave') { print "Environment will be : ${env.NODE_ENV}" build_tag = public_repo_commit_hash + "_" + env.BUILD_NUMBER + "_bot" - if (params.private_bot_repo && params.private_bot_tag) { + if (params.private_bot_repo) { sh('cp -r bot_repo/* .') build_tag = public_repo_commit_hash + "_" + private_repo_commit_hash + "_" + env.BUILD_NUMBER + "_bot" }