-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathJenkinsfile
More file actions
111 lines (101 loc) · 3.97 KB
/
Jenkinsfile
File metadata and controls
111 lines (101 loc) · 3.97 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
pipeline {
agent none
options {
buildDiscarder logRotator(artifactDaysToKeepStr: '', artifactNumToKeepStr: '5', daysToKeepStr: '90', numToKeepStr: '')
}
environment {
GHCR_IMAGE_BASE = 'ghcr.io/intranda/goobi-viewer-theme-reference'
DOCKERHUB_IMAGE_BASE = 'intranda/goobi-viewer-theme-reference'
NEXUS_IMAGE_BASE = 'nexus.intranda.com:4443/goobi-viewer-theme-reference'
}
stages {
stage('build') {
agent {
docker {
image 'maven:3-eclipse-temurin-21'
args '-v $HOME/.m2:/var/maven/.m2:z -u 1000 -ti -e _JAVA_OPTIONS=-Duser.home=/var/maven -e MAVEN_CONFIG=/var/maven/.m2'
}
}
steps {
sh 'git clean -fdx'
sh 'mvn -f goobi-viewer-theme-reference/pom.xml clean verify'
recordIssues enabledForFailure: true, aggregatingResults: true, tools: [java(), javaDoc()]
archiveArtifacts artifacts: '**/target/*.war', fingerprint: true, onlyIfSuccessful: true
stash includes: '**/target/*.war', name: 'app'
}
}
stage('build and and publish docker image with corresponding config') {
agent any
when {
anyOf {
tag "v*"
branch 'develop'
expression { return env.BRANCH_NAME =~ /_docker$/ }
}
}
steps {
// get viewer.war from build stage
unstash 'app'
withCredentials([
usernamePassword(
credentialsId: 'jenkins-github-container-registry',
usernameVariable: 'GHCR_USER',
passwordVariable: 'GHCR_PASS'
),
usernamePassword(
credentialsId: '0b13af35-a2fb-41f7-8ec7-01eaddcbe99d',
usernameVariable: 'DOCKERHUB_USER',
passwordVariable: 'DOCKERHUB_PASS'
),
usernamePassword(
credentialsId: 'jenkins-docker',
usernameVariable: 'NEXUS_USER',
passwordVariable: 'NEXUS_PASS'
)
]) {
sh '''
# Login to registries
echo "$GHCR_PASS" | docker login ghcr.io -u "$GHCR_USER" --password-stdin
echo "$DOCKERHUB_PASS" | docker login docker.io -u "$DOCKERHUB_USER" --password-stdin
echo "$NEXUS_PASS" | docker login nexus.intranda.com:4443 -u "$NEXUS_USER" --password-stdin
# Setup QEMU and Buildx
docker buildx create --name multiarch-builder --use || docker buildx use multiarch-builder
docker buildx inspect --bootstrap
CONFIG_BRANCH_NAME=develop
# Tag logic
TAGS=""
if [ ! -z "$TAG_NAME" ]; then
CONFIG_BRANCH_NAME=master
TAGS="$TAGS -t $GHCR_IMAGE_BASE:$TAG_NAME -t $DOCKERHUB_IMAGE_BASE:$TAG_NAME -t $NEXUS_IMAGE_BASE:$TAG_NAME -t $GHCR_IMAGE_BASE:latest -t $DOCKERHUB_IMAGE_BASE:latest -t $NEXUS_IMAGE_BASE:latest"
elif [ "$GIT_BRANCH" = "origin/develop" ] || [ "$GIT_BRANCH" = "develop" ]; then
TAGS="$TAGS -t $GHCR_IMAGE_BASE:develop -t $DOCKERHUB_IMAGE_BASE:develop -t $NEXUS_IMAGE_BASE:develop"
elif echo "$GIT_BRANCH" | grep -q "_docker$"; then
TAG_SUFFIX=$(echo "$GIT_BRANCH" | sed 's/_docker$//' | sed 's|/|_|g')
TAGS="$TAGS -t $GHCR_IMAGE_BASE:$TAG_SUFFIX -t $DOCKERHUB_IMAGE_BASE:$TAG_SUFFIX -t $NEXUS_IMAGE_BASE:$TAG_SUFFIX"
else
echo "No matching tag, skipping build."
exit 0
fi
# Build and push to all registries
docker buildx build --build-arg build=false \
--no-cache --build-arg CONFIG_BRANCH=$CONFIG_BRANCH_NAME \
--platform linux/amd64,linux/arm64/v8,linux/ppc64le,linux/riscv64,linux/s390x \
$TAGS \
--push .
'''
}
}
}
}
post {
changed {
emailext(
subject: '${DEFAULT_SUBJECT}',
body: '${DEFAULT_CONTENT}',
recipientProviders: [requestor(),culprits()],
attachLog: true
)
}
}
}
/* vim: set ts=2 sw=2 tw=120 et :*/