-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathJenkinsfile
More file actions
80 lines (79 loc) · 1.75 KB
/
Copy pathJenkinsfile
File metadata and controls
80 lines (79 loc) · 1.75 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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
pipeline {
agent {
label 'docker'
}
options {
buildDiscarder(logRotator(numToKeepStr: '5'))
disableConcurrentBuilds()
ansiColor('xterm')
}
environment {
IMAGE = 'fakebambu'
BUILDX_NAME = "${IMAGE}_${GIT_BRANCH}"
BRANCH_LOWER = "${BRANCH_NAME.toLowerCase().replaceAll('/', '-')}"
}
stages {
stage('Environment') {
parallel {
stage('Master') {
when {
branch 'master'
}
steps {
script {
env.TAG = "latest"
env.BUILDX_PUSH_TAGS = "-t docker.io/jc21/${IMAGE}:${TAG}"
}
}
}
stage('Other') {
when {
not {
branch 'master'
}
}
steps {
script {
// Defaults to the Branch name, which is applies to all branches AND pr's
env.TAG = "github-${BRANCH_LOWER}"
env.BUILDX_PUSH_TAGS = "-t docker.io/jc21/${IMAGE}:${TAG}"
}
}
}
}
}
stage('Buildx') {
environment {
BUILDX_NAME = "${IMAGE}_${GIT_BRANCH}"
}
steps {
withCredentials([usernamePassword(credentialsId: 'jc21-dockerhub', passwordVariable: 'DOCKER_PASS', usernameVariable: 'DOCKER_USER')]) {
sh 'docker login -u "${DOCKER_USER}" -p "${DOCKER_PASS}"'
sh "./scripts/buildx.sh --push -f docker/Dockerfile ${BUILDX_PUSH_TAGS}"
}
}
}
stage('PR Comment') {
when {
allOf {
changeRequest()
not {
equals expected: 'UNSTABLE', actual: currentBuild.result
}
}
}
steps {
script {
def comment = pullRequest.comment("""Docker Image for build ${BUILD_NUMBER} is available on [DockerHub](https://cloud.docker.com/repository/docker/jc21/${IMAGE}) as:
- `jc21/${IMAGE}:github-${BRANCH_LOWER}`
""")
}
}
}
}
post {
always {
printResult(true)
}
}
}