forked from netlify/build-image
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Jenkinsfile
76 lines (69 loc) · 2.21 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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
pipeline {
agent any
stages {
stage("Test Build") {
when {
not { anyOf { branch 'staging' ; branch 'xenial' ; branch 'trusty ' ; buildingTag() } }
}
steps {
sh "docker build --build-arg NF_IMAGE_VERSION=${env.GIT_COMMIT} ."
}
}
stage("Build Tags and Special Branches") {
when {
anyOf { branch 'staging' ; branch 'xenial' ; branch 'trusty' ; buildingTag() }
}
steps {
sh "docker build --build-arg NF_IMAGE_VERSION=${env.GIT_COMMIT} --build-arg NF_IMAGE_TAG=${env.BRANCH_NAME} -t netlify/build:${env.BRANCH_NAME} -t netlify/build:${env.GIT_COMMIT} ."
}
}
stage("Build Squash images") {
when {
anyOf { buildingTag() }
}
steps {
sh "docker build --build-arg NF_IMAGE_VERSION=${env.GIT_COMMIT} --build-arg NF_IMAGE_TAG=${env.BRANCH_NAME} --squash -t netlify/build:${env.BRANCH_NAME}-squash ."
}
}
stage("Push Images") {
when {
anyOf { branch 'staging' ; branch 'xenial' ; branch 'trusty' ; buildingTag()}
}
steps {
script {
docker.withRegistry('https://index.docker.io/v1/', 'docker-hub-ci') {
docker.image("netlify/build:${env.BRANCH_NAME}").push()
docker.image("netlify/build:${env.GIT_COMMIT}").push()
}
}
}
}
stage("Push Squash Images") {
when {
anyOf { buildingTag() }
}
steps {
script {
docker.withRegistry('https://index.docker.io/v1/', 'docker-hub-ci') {
docker.image("netlify/build:${env.BRANCH_NAME}-squash").push()
}
}
}
}
}
post {
failure {
slackSend color: "danger", message: "Build failed - ${env.JOB_NAME} ${env.BUILD_NUMBER} (<${env.BUILD_URL}/console|Open>)"
}
success {
slackSend color: "good", message: "Build succeeded - ${env.JOB_NAME} ${env.BUILD_NUMBER} (<${env.BUILD_URL}/console|Open>)"
}
}
}
/*
Jenkins ENV Reference:
env.GIT_COMMIT: the commit sha of the current build
env.BRANCH_NAME: the branch name OR tag name of the current build, when it exists
env.GIT_BRANCH: same as BRANCH_NAME
env.TAG_NAME: the tag name of the current build, when it exists
*/