-
Notifications
You must be signed in to change notification settings - Fork 0
/
Jenkinsfile
70 lines (63 loc) · 1.93 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
String registryEndpoint = 'registry.comp.ystv.co.uk'
def branch = env.BRANCH_NAME.replaceAll("/", "_")
def image
String imageName = "ystv/stv-web:${branch}-${env.BUILD_ID}"
pipeline {
agent {
label 'docker'
}
environment {
REGISTRY_ENDPOINT = credentials('docker-registry-endpoint')
}
stages {
stage('Build image') {
steps {
script {
GIT_COMMIT_HASH = sh (script: "git log -n 1 --pretty=format:'%H'", returnStdout: true)
docker.withRegistry('https://' + registryEndpoint, 'docker-registry') {
image = docker.build(imageName, "--build-arg COMP_SITE_VERSION_ARG=${env.BRANCH_NAME}-${env.BUILD_ID} --build-arg COMP_SITE_COMMIT_ARG=${GIT_COMMIT_HASH} .")
}
}
}
}
stage('Push image to registry') {
steps {
script {
docker.withRegistry('https://' + registryEndpoint, 'docker-registry') {
image.push()
if (env.BRANCH_IS_PRIMARY) {
image.push('latest')
}
}
}
}
}
stage('Deploy') {
stages {
stage('Development') {
when {
expression { env.BRANCH_IS_PRIMARY }
}
steps {
build(job: 'Deploy Nomad Job', parameters: [
string(name: 'JOB_FILE', value: 'stv-dev.nomad'),
text(name: 'TAG_REPLACEMENTS', value: "${registryEndpoint}/${imageName}")
])
}
}
stage('Production') {
when {
// Checking if it is semantic version release.
expression { return env.TAG_NAME ==~ /v(0|[1-9]\d*)\.(0|[1-9]\d*)\.(0|[1-9]\d*)/ }
}
steps {
build(job: 'Deploy Nomad Job', parameters: [
string(name: 'JOB_FILE', value: 'stv-prod.nomad'),
text(name: 'TAG_REPLACEMENTS', value: "${registryEndpoint}/${imageName}")
])
}
}
}
}
}
}