Search

bigdata

pipeline { agent { label 'master' } environment { // CI 변수 GIT_CREDENTIALS_ID = "test1" GIT_URL = "gitlab.paas.smes-tipa.go.kr/test1/bigdataplatform.git" // http:// 또는 https:// 제거 BRANCH="master" // Path Directory 변수 및 웹 도메인 변수 지정 MAINNAME = "bigdata" DOMAIN = "www.smes.go.kr" DIRPATH = "bigdata" // CF LOGIN 변수 PAASTA_CREDENTIAL_ID = "paasta-admin" CF_ORG_NAME = "중소벤처24시스템_운영" CF_SPACE_NAME = "지능형플랫폼" // Sonarqube 변수 SONARQUBE_TOKEN_ID = "helpdesk-sonarqube-token" //CF PUSH를 위한 변수 CF_API_URL = "https://api.paas.smes-tipa.go.kr" CF_MANIFEST = "manifest.yml" CF_SUBDOMAIN = "spring-maven" CF_DOMAIN = "paas.smes-tipa.go.kr" } tools { jdk 'OpenJDK11' gradle "gradle-7.3" } stages { stage('Preset') { steps { script { try { def now = new Date() CREATED = now.format("yyyy-MM-dd:HH.mm.ss", TimeZone. getTimeZone('Asia/Seoul')).replace(':', 'T') NEW_VERSION="${CREATED}" env.preambleResult = true echo "${NEW_VERSION}" } catch(Exception e) { cleanWs() PrintErrorMessage(e) currentBuild.result = 'FAILURE' } } } } stage("01. git clone") { steps { script { try { git credentialsId: "${GIT_CREDENTIALS_ID}", url: "http://${GIT_URL}", branch: "${BRANCH}", poll: true, changelog: true env.gitcloneResult = true } catch(Exception e) { cleanWs() PrintErrorMessage(e) currentBuild.result = 'FAILURE' } } } } stage ("02. gradle build test") { steps { script { try { /*dir ('back-end') { sh 'gradle build -x test --stacktrace' env.buildSourceResult = true }*/ sh 'gradle build -x test --stacktrace' /* sh 'gradle build -x test --debug'*/ env.buildSourceResult = true } catch(Exception e) { addComment("Build Source 스테이지에서 실패했습니다.") cleanWs() PrintErrorMessage(e) currentBuild.result = 'FAILURE' } } } } /* stage("03-Static Code Analysis") { steps { echo '03-Static Code Analysis..' script { try { dir ('back-end') { withSonarQubeEnv(credentialsId: "${SONARQUBE_TOKEN_ID}", installationName: 'sonarcube8.3.1') { sh 'gradle sonarqube -Dsonar.projectKey=heldesk -Dsonar.host.url=http://sonarqube.paas.smes-tipa.go.kr:9000 -Dsonar.login=c51130b29b1390e68c011a77d7b92f395874d7e8 -x test --stacktrace' } } } catch(Exception e) { addComment("Static Code Analysis 스테이지에서 실패했습니다.") cleanWs() PrintErrorMessage(e) currentBuild.result = 'FAILURE' } } } } stage("04-Code Quality Gate") { steps { script { try { dir ('back-end') { def qualitygate = waitForQualityGate(abortPipeline: true, webhookSecretId: 'jenkin-sonarqube-webhook') if (qualitygate.status != "OK") { error "Pipeline aborted due to quality gate coverage failure: ${qualitygate.status}" } } } catch(Exception e) { addComment("Code Quality Gate 스테이지에서 실패했습니다.") cleanWs() PrintErrorMessage(e) currentBuild.result = 'FAILURE' } } } } */ stage ('04. Create manifest.yml for cf app') { steps{ script { try { sh(""" cat > manifest.yml <<EOF --- applications: - name: ${MAINNAME} memory: 2048MB instances: 1 routes: - route: ${DOMAIN}/${DIRPATH} buildpacks: - java_buildpack_offline_v2 env: JBP_CONFIG_OPEN_JDK_JRE: '{ jre: { version: 11.+}}' path: build/libs/intelligentPlatform-0.1.jar EOF """) } catch(Exception e) { cleanWs() PrintErrorMessage(e) currentBuild.result = 'FAILURE' } } } } stage('05-CF app deploy') { steps { echo '06-CF app deploy..' script { try { withCredentials([usernamePassword(credentialsId: "${PAASTA_CREDENTIAL_ID}", passwordVariable: 'passta_password', usernameVariable: 'passta_username')]) { def lastSuccessfulBuildID = 0 def build = currentBuild.previousBuild while (build != null) { if (build.result == "SUCCESS") { lastSuccessfulBuildID = build.id //as Integer break } build = build.previousBuild } sh "cf login -a ${CF_API_URL} -u ${passta_username} -p ${passta_password} -o ${CF_ORG_NAME} -s ${CF_SPACE_NAME} --skip-ssl-validation" sh "cf push -f ${CF_MANIFEST}" //sh "cf delete-route -f ${CF_DOMAIN} --hostname ${CF_SUBDOMAIN}" //sh "cf map-route ${PROJECT}${BUILD_NUMBER} ${CF_DOMAIN} --hostname ${CF_SUBDOMAIN}" //sh "cf unmap-route ${PROJECT}${lastSuccessfulBuildID} ${CF_DOMAIN} --hostname ${CF_SUBDOMAIN}" //sh "cf logout" } } catch(Exception e) { addComment("CF app deploy 스테이지에서 실패했습니다.") cleanWs() PrintErrorMessage(e) currentBuild.result = 'FAILURE' } } } } stage('06. clean up workspace') { steps { step([$class: 'WsCleanup']) } } } }
Shell
복사