-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathJenkinsfile.docker
More file actions
64 lines (55 loc) · 1.79 KB
/
Jenkinsfile.docker
File metadata and controls
64 lines (55 loc) · 1.79 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
pipeline {
agent {
label 'vm-docker'
}
environment {
REGISTRY = 'ghcr.io'
IMAGE_NAME = 'git-stuff-done/endpoint-insights-api'
}
stages {
stage('Checkout') {
steps {
checkout scm
}
}
stage('Build') {
steps {
script {
def tags = "-t ${REGISTRY}/${IMAGE_NAME}:${GIT_COMMIT} -t ${REGISTRY}/${IMAGE_NAME}:${BRANCH_NAME}"
if (BRANCH_NAME == 'main') {
tags += " -t ${REGISTRY}/${IMAGE_NAME}:latest"
}
sh """
docker build -f ./endpoint-insights-api/Dockerfile ${tags} .
"""
}
}
}
stage('Push') {
steps {
script {
withCredentials([usernamePassword(
credentialsId: 'docker-registry-creds',
usernameVariable: 'DOCKER_USER',
passwordVariable: 'DOCKER_PASS'
)]) {
sh """
echo \$DOCKER_PASS | docker login ${REGISTRY} -u \$DOCKER_USER --password-stdin
docker push ${REGISTRY}/${IMAGE_NAME}:${GIT_COMMIT}
docker push ${REGISTRY}/${IMAGE_NAME}:${BRANCH_NAME}
"""
if (BRANCH_NAME == 'main') {
sh "docker push ${REGISTRY}/${IMAGE_NAME}:latest"
}
}
}
}
}
}
post {
always {
sh "docker logout ${REGISTRY} || true"
sh "docker image prune -f || true"
}
}
}