From 560c0c966363ac3338d8dbdff9d359a49d025f74 Mon Sep 17 00:00:00 2001 From: crusader Date: Wed, 1 Feb 2023 11:07:00 +0000 Subject: [PATCH] environment test --- Jenkinsfile | 55 +++++++++++++++++++++++++++++++++++++++-------------- 1 file changed, 41 insertions(+), 14 deletions(-) diff --git a/Jenkinsfile b/Jenkinsfile index 03f1cbb..5e3c18c 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -1,20 +1,47 @@ -podTemplate(containers: [ - containerTemplate( - name: 'gradle', - image: 'gradle:7.6.0-jdk11', - command: 'sleep', - args: '30d' - ) - ]) { +def label = "worker-${UUID.randomUUID().toString()}" - node(POD_LABEL) { - stage('Get a Gradle project') { - container('gradle') { - stage('Build a Gradle project') { - sh './gradlew clean build' +podTemplate( + label: label + containers: [ + containerTemplate( + name: 'gradle', + image: 'gradle:7.6.0-jdk11', + command: 'sleep', + args: '30d' + ) + ], + volumes: [ + hostPathVolume(mountPath: '/home/gradle/.gradle', hostPath: '/tmp/jenkins/.gradle') + ] +) +{ + node(label) { + 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') { + sh "gradle build" + } } - } }