Repository navigation
Expand file tree
/
Copy pathJenkinsfile
More file actions
52 lines (44 loc) · 1.41 KB
/
Copy pathJenkinsfile
File metadata and controls
52 lines (44 loc) · 1.41 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
pipeline {
agent any
environment {
DOCKER_REGISTRY = 'git.janpeterdhalle.com'
IMAGE_NAME = 'jp-transfer-service'
GIT_USERNAME = 'jp'
}
tools {
jdk 'java21'
maven 'maven3'
}
stages {
stage('Checkout') {
steps {
checkout scm
}
}
stage('Build with Maven') {
steps {
sh 'mvn -B clean package'
}
}
stage('Docker Build & Push') {
steps {
script {
// Default tag
def imageTag = "latest"
// If current branch is 'develop', append _dev
if (env.BRANCH_NAME == "develop") {
imageTag = "latest_dev"
}
def fullImage = "${DOCKER_REGISTRY}/${GIT_USERNAME}/${IMAGE_NAME}:${imageTag}"
withCredentials([usernamePassword(credentialsId: 'forgejo', usernameVariable: 'DOCKER_USER', passwordVariable: 'DOCKER_PASS')]) {
sh """
echo "\$DOCKER_PASS" | docker login \$DOCKER_REGISTRY -u "\$DOCKER_USER" --password-stdin
docker build -t ${fullImage} .
docker push ${fullImage}
"""
}
}
}
}
}
}