-
Notifications
You must be signed in to change notification settings - Fork 0
/
Jenkinsfile
94 lines (88 loc) · 4.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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
@Library('ystv-jenkins')
def imageNamePrefix = ''
pipeline {
agent {
label 'docker'
}
environment {
DOCKER_BUILDKIT = "1"
}
stages {
stage('Prepare') {
steps {
ciSkip action: 'check'
script {
if (env.BRANCH_NAME != 'main') {
imageNamePrefix = "${env.BRANCH_NAME}-"
}
}
}
}
stage('Download Dependencies') {
steps {
sh 'docker build -f Dockerfile.common .'
}
}
stage('Build Images') {
parallel {
// bundle uses a different base image because its builds are done inside of NodeCG,
// so it can't take advantage of the Dockerfile.common trick
stage('Bundle') {
steps {
withDockerRegistry(credentialsId: 'docker-registry', url: 'https://registry.comp.ystv.co.uk') {
sh "docker build --build-arg GIT_REV=${env.GIT_COMMIT} -t registry.comp.ystv.co.uk/sports-scores/bundle:${imageNamePrefix}${env.BUILD_NUMBER} -f Dockerfile.bundle ."
}
}
}
stage('Server') {
steps {
sh "docker build --build-arg GIT_REV=${env.GIT_COMMIT} -t registry.comp.ystv.co.uk/sports-scores/server:${imageNamePrefix}${env.BUILD_NUMBER} -f Dockerfile.server ."
}
}
stage('Client') {
steps {
sh "docker build --build-arg GIT_REV=${env.GIT_COMMIT} -t registry.comp.ystv.co.uk/sports-scores/client:${imageNamePrefix}${env.BUILD_NUMBER} -f Dockerfile.client ."
}
}
}
}
stage('Push') {
steps {
withDockerRegistry(credentialsId: 'docker-registry', url: 'https://registry.comp.ystv.co.uk') {
sh "docker push registry.comp.ystv.co.uk/sports-scores/client:${imageNamePrefix}${env.BUILD_NUMBER}"
sh "docker push registry.comp.ystv.co.uk/sports-scores/server:${imageNamePrefix}${env.BUILD_NUMBER}"
sh "docker push registry.comp.ystv.co.uk/sports-scores/bundle:${imageNamePrefix}${env.BUILD_NUMBER}"
script {
if (env.BRANCH_NAME == 'main') {
sh "docker tag registry.comp.ystv.co.uk/sports-scores/client:${imageNamePrefix}${env.BUILD_NUMBER} registry.comp.ystv.co.uk/sports-scores/client:latest"
sh "docker tag registry.comp.ystv.co.uk/sports-scores/server:${imageNamePrefix}${env.BUILD_NUMBER} registry.comp.ystv.co.uk/sports-scores/server:latest"
sh "docker tag registry.comp.ystv.co.uk/sports-scores/bundle:${imageNamePrefix}${env.BUILD_NUMBER} registry.comp.ystv.co.uk/sports-scores/bundle:latest"
sh 'docker push registry.comp.ystv.co.uk/sports-scores/client:latest'
sh 'docker push registry.comp.ystv.co.uk/sports-scores/server:latest'
sh 'docker push registry.comp.ystv.co.uk/sports-scores/bundle:latest'
}
}
}
}
}
stage('Deploy to development') {
when {
branch 'main'
}
steps {
build job: 'Deploy Nomad Job', parameters: [
string(name: 'JOB_FILE', value: 'sports-graphics.nomad'),
text(name: 'TAG_REPLACEMENTS', value: "registry.comp.ystv.co.uk/sports-scores/server:${env.BUILD_NUMBER} registry.comp.ystv.co.uk/sports-scores/client:${env.BUILD_NUMBER}")
]
build job: 'Deploy Nomad Job', parameters: [
string(name: 'JOB_FILE', value: 'sports-graphics-bundle.nomad'),
text(name: 'TAG_REPLACEMENTS', value: "registry.comp.ystv.co.uk/sports-scores/bundle:${env.BUILD_NUMBER}")
]
}
}
}
post { always {
ciSkip action: 'postProcess'
cleanWs()
}}
}