This repository has been archived by the owner on Jan 25, 2023. It is now read-only.
/
Jenkinsfile
57 lines (52 loc) · 1.84 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
stages {
stage("Test Build") {
when {
not { anyOf { branch 'master' ; branch 'staging' ; buildingTag() } }
}
steps {
sh "docker build --build-arg NF_IMAGE_VERSION=${env.GIT_COMMIT} ."
}
}
stage("Build Tags and Special Branches") {
when {
anyOf { branch 'master' ; branch 'staging' ; buildingTag() }
}
steps {
sh "docker build --build-arg NF_IMAGE_VERSION=${env.GIT_COMMIT} -t netlify/build:${env.BRANCH_NAME} -t netlify/build:${env.GIT_COMMIT} ."
sh "docker build --build-arg NF_IMAGE_VERSION=${env.GIT_COMMIT} --squash -t netlify/build:${env.BRANCH_NAME}-squash -t netlify/build:${env.GIT_COMMIT}-squash ."
}
}
stage("Push Images") {
when {
anyOf { branch 'master' ; branch 'staging' ; 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()
docker.image("netlify/build:${env.BRANCH_NAME}-squash").push()
docker.image("netlify/build:${env.GIT_COMMIT}-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
*/