From 6c4420e5b44c76d519c0440a02171bcfc291ce55 Mon Sep 17 00:00:00 2001 From: crusader Date: Wed, 1 Feb 2023 08:18:35 +0000 Subject: [PATCH] environment test --- Jenkinsfile | 45 ++++++++++++++++++++++++++++++++++----------- 1 file changed, 34 insertions(+), 11 deletions(-) diff --git a/Jenkinsfile b/Jenkinsfile index c0bebf2..c8439f4 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -5,21 +5,44 @@ def NAMESPACE = "ns-project" def VERSION = "${env.BUILD_NUMBER}" def DATE = new Date(); -podTemplate(label: 'builder', - containers: [ - containerTemplate(name: 'gradle', image: 'gradle:7.6-jdk11', command: 'cat', ttyEnabled: true), - ], - volumes: [ - hostPathVolume(mountPath: '/home/gradle/.gradle', hostPath: '/tmp/jenkins/.gradle'), - ]) { +podTemplate( + label: 'builder', + containers: [ + containerTemplate(name: 'gradle', image: 'gradle:7.6-jdk11', command: 'cat', ttyEnabled: true), + ], + volumes: [ + hostPathVolume(mountPath: '/home/gradle/.gradle', hostPath: '/tmp/jenkins/.gradle'), + ] +) + +{ node('builder') { - stage('Checkout') { - checkout scm // gitlab으로부터 소스 다운 + def myRepo = checkout scm + def gitCommit = myRepo.GIT_COMMIT + def gitBranch = myRepo.GIT_BRANCH + def shortGitCommit = "${gitCommit[0..10]}" + def previousGitCommit = sh(script: "git rev-parse ${gitCommit}~", returnStdout: true) + + stage('Test') { + try { + container('gradle') { + sh """ + pwd + echo "GIT_BRANCH=${gitBranch}" >> /etc/environment + echo "GIT_COMMIT=${gitCommit}" >> /etc/environment + gradle test + """ + } + } + catch (exc) { + println "Failed to test - ${currentBuild.fullDisplayName}" + throw(exc) + } } + stage('Build') { container('gradle') { - /* 도커 이미지를 활용하여 gradle 빌드를 수행하여 ./build/libs에 jar파일 생성 */ - sh "gradle -x test build" + sh "gradle build" } } }