-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathJenkinsfile
60 lines (50 loc) · 1.79 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
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 Build and Push Multi-Arch') {
steps {
script {
withCredentials([usernamePassword(credentialsId: DOCKER_CREDENTIALS_ID,
passwordVariable: 'DOCKER_PASS', usernameVariable: 'DOCKER_USER')]) {
sh """
BUILDER_NAME=\$(docker buildx create --driver docker-container)
docker buildx use \$BUILDER_NAME
docker buildx inspect --bootstrap
# Login
echo "\$DOCKER_PASS" | docker login -u "\$DOCKER_USER" --password-stdin
# Build & push multi-arch
docker buildx build \\
--platform linux/amd64,linux/arm64 \\
-t ${DOCKER_IMAGE} \\
--push .
# Logout
docker logout
# Remove the ephemeral builder
docker buildx rm \$BUILDER_NAME || true
"""
}
}
}
}
stage('Cleanup') {
steps {
sh "docker system prune -f"
}
}
}
}