pipeline { environment { //BRANCH_NAME = '' ENVIRONMENT = 'Staging' PROJECTKEY = 'PUL' } agent { label "master" } stages { stage ("cleanWS") { steps{ timestamps { script { cleanWs() } } } } stage ("Checkout") { steps{ script { if (ENVIRONMENT.equals ("Staging")) { checkout([$class: 'GitSCM', branches: [[name: BRANCH_NAME ]], doGenerateSubmoduleConfigurations: false, extensions: [[$class: 'LocalBranch', localBranch: BRANCH_NAME ]], submoduleCfg: [], userRemoteConfigs: [[credentialsId: 'jenkins_gitlab_user', url: 'ssh://git@auapgpdgitapp01.genpt.net/Pulse/PulseUI.git']]]) checkout changelog: false, poll: false, scm: [$class: 'GitSCM', branches: [[name: '*/master']], doGenerateSubmoduleConfigurations: false, extensions: [[$class: 'RelativeTargetDirectory', relativeTargetDir: 'scm']], submoduleCfg: [], userRemoteConfigs: [[credentialsId: 'jenkins_gitlab_user', url: 'ssh://git@auapgpdgitapp01.genpt.net/SCM/APGCM.git']]] //Auto Increment Version withEnv(["BRANCH_NAME=${BRANCH_NAME}","WORKSPACE=${WORKSPACE}"]) { sh ''' whoami cp $WORKSPACE/scm/PULSE/AutoIncrementVersionPulseUI.sh $WORKSPACE chmod 775 AutoIncrementVersionPulseUI.sh BUILD_VERSION_TXT="BUILD_VERSION_TXT.txt" TAG_VERSION="TAG_VERSION.txt" #MAX_BUILD_TAG=$(mysql -h 10.5.128.173 -u"${MYSQL_ROOT_USER_ID}" -p"${MYSQL_ROOT_PSWD}" --database=wikireports -se "select buildName from wikireports.buildmetrics where issueID='${JIRA_ISSUE_ID}' order by buildName DESC LIMIT 1") MAX_BUILD_TAG="" if [[ -z ${MAX_BUILD_TAG} ]]; then #SET MAX_BUILD_TAG NOT AVAILABLE MAX_BUILD_TAG="NA" fi echo ${MAX_BUILD_TAG} ./AutoIncrementVersionPulseUI.sh ${BRANCH_NAME} ${MAX_BUILD_TAG} ${BUILD_VERSION_TXT} ${TAG_VERSION} ''' BUILD_VERSION=sh (returnStdout: true, script: '''BUILD_VERSION=\$(cat BUILD_VERSION_TXT.txt) && echo "${BUILD_VERSION}"''') BUILD_VERSION_NUM=sh (returnStdout: true, script: '''BUILD_VERSION_NUM=\$(cat BUILD_VERSION_TXT.txt | sed s/v.//g | tr -d '\040\011\012\015' ) && echo "${BUILD_VERSION_NUM}"''') BUILD_VERSIONS_DIR=sh (returnStdout: true, script: '''BUILD_VERSIONS_DIR=\$(cat TAG_VERSION.txt | head -1 | awk -F '=' '{print \$2}') && echo "${BUILD_VERSIONS_DIR}"''') } } else if (ENVIRONMENT.equals ("Production")) { print "Skippping SourcdeCheckout, But chekcing pulse process clean up script from config repo" checkout changelog: false, poll: false, scm: [$class: 'GitSCM', branches: [[name: '*/master']], doGenerateSubmoduleConfigurations: false, extensions: [[$class: 'RelativeTargetDirectory', relativeTargetDir: 'scm']], submoduleCfg: [], userRemoteConfigs: [[credentialsId: 'jenkins_gitlab_user', url: 'ssh://git@auapgpdgitapp01.genpt.net/SCM/APGCM.git']]] } } } } //End of Checkout Stage stage ("BUILD") { steps{ timestamps { script { if (ENVIRONMENT.equals ("Staging")) { wrap([$class: 'MaskPasswordsBuildWrapper']) { def buildEnv= [QA_US: "-PQA -PUS-QA", QA_UAP: "-PQA -PUAP-QA", PROD_US: "-PPROD -PUS-PROD", PROD_UAP: "-PPROD -PUAP-PROD"] //def buildEnv= [QA_US: "-PQA -PUS-QA"] buildEnv.each{ targetEnv = it.key targetBuildEnv = it.value stage ( "${targetEnv}_Build" ) { withEnv(["targetBuildEnv=${targetBuildEnv}","BUILD_VERSION_NUM=${BUILD_VERSION_NUM}"]) { sh ''' /usr/local/apache-maven-3.3.9/bin/mvn versions:set -DnewVersion=${BUILD_VERSION_NUM} docker run -i --rm --name pulsebuilder -v "$(pwd)":/home/pulsebuilder/PulseUI -w /home/pulsebuilder/PulseUI gpcpulse/pulse:pulsebuilder_latest mvn clean install $targetBuildEnv -X -Ddeployarchive=true -Ddeploy.server.ip=10.5.128.163 -Ddeploy.server.user=$BUILD01_USER -Ddeploy.server.pass=$BUILD01_CRED -Dmaven.test.skip -Dmaven.exec.skip=false #docker run -i --rm --name pulsebuilder -v "$(pwd)":/home/pulsebuilder/PulseUI -w /home/pulsebuilder/PulseUI gpcpulse/pulse:pulsebuilder_1.0.0 mvn clean install $targetBuildEnv -X #-Dmaven.test.skip -Dmaven.exec.skip=false whoami sudo rm -rf src/main/webapp/app/node_modules sudo rm -rf target/ ''' } } } } // End of wrap class } else if (ENVIRONMENT.equals ("Production")) { print "Skippping BUILD Stage" } } //End of Scripts } } } //End of Build Scripts stage ("Archive") { steps{ timestamps { script { if (ENVIRONMENT.equals ("Staging")) { wrap([$class: 'MaskPasswordsBuildWrapper']) { def buildServer= [BUILD01: "AUAPGPDARCAPP01"] buildServer.each{ targetEnv = it.key targetServer = it.value stage ( "${targetEnv}_Archive" ) { withEnv(["targetServer=${targetServer}","BUILD_VERSION_NUM=${BUILD_VERSION_NUM}","BUILD_VERSIONS_DIR=${BUILD_VERSIONS_DIR}"]) { sh ''' sshpass -p $BUILD01_CRED ssh -T -o StrictHostKeyChecking=no maint@AUAPGPDARCAPP01.genpt.net "cd /home/Pulse/PulseUI && BUILD_VERSIONS_NUM="$(echo ${BUILD_VERSION_NUM} | head -1 | tr -d '\040\011\012\015' | tr -d '[:space:]')" && BUILD_VERSIONS_DIR=$(echo ${BUILD_VERSIONS_DIR}) && mkdir "$(echo $BUILD_VERSIONS_DIR)" && mv $(echo $BUILD_VERSIONS_DIR)-* $(echo $BUILD_VERSIONS_DIR)/" ''' } } } } } else if (ENVIRONMENT.equals ("Production")) { print "Skipping Archive Stage" } } } } } } //End of Stages } //End of Pipeline