Skip to content

Commit 87cacad

Browse files
committed
Refactor Jenkins CI build (Jenkinsfile) to use ci/pipeline.properties to parameterize the build.
* Map and set the 'jenkins' user home directory (/home/jenkins) on the host (Jenkins server / worker node) filesystem to the Docker Container (virtual) filesystem's /tmp/jenkins-home directory. * Change Docker Container 'inside' environment settings when deploying artifacts and docs to no longer set the '--name' option.
1 parent 0f3945a commit 87cacad

File tree

5 files changed

+32
-20
lines changed

5 files changed

+32
-20
lines changed

Jenkinsfile

Lines changed: 15 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
1+
def p = [:]
2+
3+
node {
4+
checkout scm
5+
p = readProperties interpolate: true, file: 'ci/pipeline.properties'
6+
}
7+
18
pipeline {
29

310
agent any
411

5-
/*
6-
environment {
7-
JAVA_HOME = "${tool 'jdk8'}"
8-
}
9-
*/
10-
1112
options {
1213
buildDiscarder(logRotator(numToKeepStr: '15'))
1314
disableConcurrentBuilds()
@@ -20,16 +21,13 @@ pipeline {
2021
stages {
2122

2223
stage('Build') {
23-
environment {
24-
DOCKER_HUB = credentials('hub.docker.com-springbuildmaster')
25-
}
2624
options {
2725
timeout(time: 15, unit: "MINUTES")
2826
}
2927
steps {
3028
script {
31-
docker.withRegistry('', 'hub.docker.com-springbuildmaster') {
32-
docker.image('eclipse-temurin:17.0.1_12-jdk').inside('-u root -v /usr/bin/docker:/usr/bin/docker -v /var/run/docker.sock:/var/run/docker.sock -v /tmp:/tmp') {
29+
docker.withRegistry(p['docker.registry'], p['docker.credentials']) {
30+
docker.image(p['docker.container.image.java.main']).inside(p['docker.container.inside.env.full']) {
3331

3432
sh "echo 'Setup build environment...'"
3533
sh "ci/setup.sh"
@@ -66,8 +64,8 @@ pipeline {
6664
}
6765
steps {
6866
script {
69-
docker.withRegistry('', 'hub.docker.com-springbuildmaster') {
70-
docker.image('eclipse-temurin:17.0.1_12-jdk').inside("--name ${env.HOSTNAME}Two -u root -v /tmp:/tmp") {
67+
docker.withRegistry(p['docker.registry'], p['docker.credentials']) {
68+
docker.image(p['docker.container.image.java.main']).inside(p['docker.container.inside.env.basic']) {
7169
withCredentials([file(credentialsId: 'docs.spring.io-jenkins_private_ssh_key', variable: 'DEPLOY_SSH_KEY')]) {
7270
try {
7371
sh "ci/deployDocs.sh"
@@ -89,12 +87,12 @@ pipeline {
8987
}
9088
steps {
9189
script {
92-
docker.withRegistry('', 'hub.docker.com-springbuildmaster') {
93-
docker.image('eclipse-temurin:17.0.1_12-jdk').inside("--name ${env.HOSTNAME}One -u root -v /tmp:/tmp") {
90+
docker.withRegistry(p['docker.registry'], p['docker.credentials']) {
91+
docker.image(p['docker.container.image.java.main']).inside(p['docker.container.inside.env.basic']) {
9492
withCredentials([file(credentialsId: 'spring-signing-secring.gpg', variable: 'SIGNING_KEYRING_FILE')]) {
9593
withCredentials([string(credentialsId: 'spring-gpg-passphrase', variable: 'SIGNING_PASSWORD')]) {
96-
withCredentials([usernamePassword(credentialsId: 'oss-token', passwordVariable: 'OSSRH_PASSWORD', usernameVariable: 'OSSRH_USERNAME')]) {
97-
withCredentials([usernamePassword(credentialsId: '02bd1690-b54f-4c9f-819d-a77cb7a9822c', usernameVariable: 'ARTIFACTORY_USERNAME', passwordVariable: 'ARTIFACTORY_PASSWORD')]) {
94+
withCredentials([usernamePassword(credentialsId: 'oss-token', usernameVariable: 'OSSRH_USERNAME', passwordVariable: 'OSSRH_PASSWORD')]) {
95+
withCredentials([usernamePassword(credentialsId: p['artifactory.credentials'], usernameVariable: 'ARTIFACTORY_USERNAME', passwordVariable: 'ARTIFACTORY_PASSWORD')]) {
9896
try {
9997
sh "ci/deployArtifacts.sh"
10098
}

ci/check.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,5 @@
22

33
set -eou pipefail
44

5-
GRADLE_OPTS="-Duser.name=jenkins -Djava.io.tmpdir=/tmp" \
5+
GRADLE_OPTS="-Duser.name=jenkins -Duser.home=/tmp/jenkins-home -Djava.io.tmpdir=/tmp" \
66
./gradlew clean check --no-daemon --refresh-dependencies --stacktrace

ci/deployArtifacts.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ echo "Deploying artifacts on host [$HOSTNAME]"
99
# Syntax: `chown -R userId:groupId .`
1010
chown -R 1001:1001 .
1111

12-
GRADLE_OPTS="-Duser.name=jenkins -Djava.io.tmpdir=/tmp" \
12+
GRADLE_OPTS="-Duser.name=jenkins -Duser.home=/tmp/jenkins-home -Djava.io.tmpdir=/tmp" \
1313
./gradlew publishArtifacts releasePublishedArtifacts --no-build-cache --no-configuration-cache --no-daemon --stacktrace \
1414
-PartifactoryUsername=$ARTIFACTORY_USERNAME \
1515
-PartifactoryPassword=$ARTIFACTORY_PASSWORD \

ci/deployDocs.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ echo "Deploying docs on host [$HOSTNAME]"
99
# Syntax: `chown -R userId:groupId .`
1010
chown -R 1001:1001 .
1111

12-
GRADLE_OPTS="--add-opens java.base/java.io=ALL-UNNAMED --add-opens java.base/sun.nio.ch=ALL-UNNAMED -Duser.name=jenkins -Djava.io.tmpdir=/tmp" \
12+
GRADLE_OPTS="--add-opens java.base/java.io=ALL-UNNAMED --add-opens java.base/sun.nio.ch=ALL-UNNAMED -Duser.name=jenkins -Duser.home=/tmp/jenkins-home -Djava.io.tmpdir=/tmp" \
1313
./gradlew deployDocs --no-daemon --stacktrace \
1414
-PdeployDocsSshKeyPath=$DEPLOY_SSH_KEY \
1515
-PdeployDocsSshUsername=$SPRING_DOCS_USERNAME

ci/pipeline.properties

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
# Java (JDK) versions
2+
java.main.tag=17.0.2_8-jdk
3+
4+
# Docker Container Images
5+
docker.container.image.java.main=harbor-repo.vmware.com/dockerhub-proxy-cache/library/eclipse-temurin:${java.main.tag}
6+
7+
# Docker Environment Settings
8+
docker.container.inside.env.basic=-u root -v $HOME:/tmp/jenkins-home -v /tmp:/tmp
9+
docker.container.inside.env.full=-u root -v /var/run/docker.sock:/var/run/docker.sock -v /usr/bin/docker:/usr/bin/docker -v /tmp:/tmp -v $HOME:/tmp/jenkins-home
10+
11+
# Credentials
12+
docker.registry=
13+
docker.credentials=hub.docker.com-springbuildmaster
14+
artifactory.credentials=02bd1690-b54f-4c9f-819d-a77cb7a9822c

0 commit comments

Comments
 (0)