-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathJenkinsfile
57 lines (51 loc) · 1.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
pipeline {
agent any
environment {
MAVEN_HOME = tool name: 'Maven', type: 'hudson.tasks.Maven$MavenInstallation'
DOCKER_IMAGE = "roastslav/quickdrop:latest"
DOCKER_CREDENTIALS_ID = 'dockerhub-credentials'
}
stages {
stage('Checkout') {
steps {
checkout scm
}
}
stage('Build and Test') {
steps {
sh "${MAVEN_HOME}/bin/mvn clean package"
}
}
stage('Docker Buildx Setup') {
steps {
script {
sh """
docker buildx create --use || echo 'Buildx already created'
docker buildx inspect --bootstrap
"""
}
}
}
stage('Docker Build and Push Multi-Arch') {
steps {
script {
withCredentials([usernamePassword(credentialsId: DOCKER_CREDENTIALS_ID, passwordVariable: 'DOCKER_PASS', usernameVariable: 'DOCKER_USER')]) {
sh """
echo "$DOCKER_PASS" | docker login -u "$DOCKER_USER" --password-stdin
docker buildx build \
--platform linux/amd64,linux/arm64 \
-t ${DOCKER_IMAGE} \
--push .
docker logout
"""
}
}
}
}
stage('Cleanup') {
steps {
sh "docker system prune -f"
}
}
}
}