forked from intranda/goobi-viewer-theme-reference
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Jenkinsfile
152 lines (137 loc) · 6 KB
/
Jenkinsfile
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
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
pipeline {
agent none
options {
buildDiscarder logRotator(artifactDaysToKeepStr: '', artifactNumToKeepStr: '15', daysToKeepStr: '90', numToKeepStr: '')
}
stages {
stage('build') {
agent {
docker {
image 'maven:3-eclipse-temurin-17'
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, test and publish docker image with config from release tag in master branch') {
agent any
when {
tag "v*"
}
steps {
// get viewer.war from build stage
unstash 'app'
// build docker images
script{
docker.withRegistry('https://nexus.intranda.com:4443','jenkins-docker'){
dockerimage = docker.build("goobi-viewer-theme-reference:${BRANCH_NAME}-${env.BUILD_ID}_${env.GIT_COMMIT}", "--no-cache --build-arg CONFIG_BRANCH=master --build-arg build=false .")
dockerimage_public = docker.build("intranda/goobi-viewer-theme-reference:${BRANCH_NAME}-${env.BUILD_ID}_${env.GIT_COMMIT}", "--build-arg CONFIG_BRANCH=master --build-arg build=false .")
}
}
// run basic tests in docker image
script {
dockerimage.inside {
sh 'test -d /usr/local/tomcat/webapps/viewer || ( echo "/usr/local/tomcat/webapps/viewer missing or no directory"; exit 1 )'
sh 'test -d /opt/digiverso/viewer || ( echo "/opt/digiverso/viewer missing or no directory"; exit 1 )'
sh 'test -f /usr/local/tomcat/conf/viewer.xml.template || ( echo "/usr/local/tomcat/conf/viewer.xml.template missing"; exit 1 )'
sh 'test -f /usr/local/tomcat/conf/server.xml.template || ( echo "/usr/local/tomcat/conf/server.xml.template missing"; exit 1 )'
sh 'test -f /usr/local/tomcat/conf/context.xml.template || ( echo "/usr/local/tomcat/conf/context.xml.template missing"; exit 1 )'
sh 'envsubst -V'
}
}
// publish docker image to internal repository
script {
docker.withRegistry('https://nexus.intranda.com:4443','jenkins-docker'){
dockerimage.push("${env.TAG_NAME}-${env.BUILD_ID}")
dockerimage.push("${env.TAG_NAME}")
dockerimage.push("latest")
}
}
// publish docker image to docker hub
script{
docker.withRegistry('','0b13af35-a2fb-41f7-8ec7-01eaddcbe99d'){
dockerimage_public.push("${env.TAG_NAME}")
dockerimage_public.push("latest")
}
}
// publish docker image to GitHub container registry
script{
docker.withRegistry('https://ghcr.io','jenkins-github-container-registry'){
dockerimage_public.push("${env.TAG_NAME}")
dockerimage_public.push("latest")
}
}
}
}
stage('build, test and publish docker image with config from develop branch') {
agent any
when {
not {
anyOf { branch 'master'; tag "v*" }
}
}
steps {
// get viewer.war from build stage
unstash 'app'
// build docker images
script{
docker.withRegistry('https://nexus.intranda.com:4443','jenkins-docker'){
dockerimage = docker.build("goobi-viewer-theme-reference:${BRANCH_NAME}-${env.BUILD_ID}_${env.GIT_COMMIT}", "--no-cache --build-arg CONFIG_BRANCH=develop --build-arg build=false .")
dockerimage_public = docker.build("intranda/goobi-viewer-theme-reference:${BRANCH_NAME}-${env.BUILD_ID}_${env.GIT_COMMIT}", "--build-arg CONFIG_BRANCH=develop --build-arg build=false .")
}
}
// run basic tests in docker image
script {
dockerimage.inside {
sh 'test -d /usr/local/tomcat/webapps/viewer || ( echo "/usr/local/tomcat/webapps/viewer missing or no directory"; exit 1 )'
sh 'test -d /opt/digiverso/viewer || ( echo "/opt/digiverso/viewer missing or no directory"; exit 1 )'
sh 'test -f /usr/local/tomcat/conf/viewer.xml.template || ( echo "/usr/local/tomcat/conf/viewer.xml.template missing"; exit 1 )'
sh 'test -f /usr/local/tomcat/conf/server.xml.template || ( echo "/usr/local/tomcat/conf/server.xml.template missing"; exit 1 )'
sh 'test -f /usr/local/tomcat/conf/context.xml.template || ( echo "/usr/local/tomcat/conf/context.xml.template missing"; exit 1 )'
sh 'envsubst -V'
}
}
// publish docker image to internal repository
script {
docker.withRegistry('https://nexus.intranda.com:4443','jenkins-docker'){
dockerimage.push("${env.BRANCH_NAME}-${env.BUILD_ID}_${env.GIT_COMMIT}")
dockerimage.push("${env.BRANCH_NAME}")
}
}
// publish docker image from develop branch to docker hub
script{
if (env.BRANCH_NAME == 'develop') {
docker.withRegistry('','0b13af35-a2fb-41f7-8ec7-01eaddcbe99d'){
dockerimage_public.push("${env.BRANCH_NAME}")
}
}
}
// publish docker image from develop branch to GitHub container registry
script{
if (env.BRANCH_NAME == 'develop') {
docker.withRegistry('https://ghcr.io','jenkins-github-container-registry'){
dockerimage_public.push("${env.BRANCH_NAME}")
}
}
}
}
}
}
post {
changed {
emailext(
subject: '${DEFAULT_SUBJECT}',
body: '${DEFAULT_CONTENT}',
recipientProviders: [requestor(),culprits()],
attachLog: true
)
}
}
}
/* vim: set ts=2 sw=2 tw=120 et :*/