-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathJenkinsfile
More file actions
65 lines (58 loc) · 2.1 KB
/
Jenkinsfile
File metadata and controls
65 lines (58 loc) · 2.1 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
def SHORT_COMMIT
def SCM_REPO
podTemplate(
imagePullSecrets: ['dockerhub-imagepull'],
containers: [
containerTemplate(
name: 'docker',
image: 'docker:20.10.15-alpine3.15',
ttyEnabled: true,
command: 'cat',
resourceRequestCpu: '200m',
resourceLimitCpu: '200m',
resourceRequestMemory: '512Mi',
resourceLimitMemory: '512Mi'),
],
volumes: [
hostPathVolume(mountPath: '/var/run/docker.sock', hostPath: '/var/run/docker.sock'),
]) {
node(POD_LABEL) {
SCM_REPO = checkout scm
DOCKERHUB_REPO = "numtechnology/modl-uk-ruby"
try {
stage('Build Container') {
container('docker') {
SHORT_COMMIT = "${SCM_REPO.GIT_COMMIT[0..6]}"
sh 'docker build --network=host -t modl-uk-ruby .'
}
}
stage('Tag Latest') {
container('docker') {
sh "docker tag modl-uk-ruby ${DOCKERHUB_REPO}:${env.BRANCH_NAME}-${SHORT_COMMIT}"
if(env.BRANCH_NAME == 'master') {
sh "docker tag modl-uk-ruby ${DOCKERHUB_REPO}:latest"
}
}
}
stage('Push Container') {
container('docker') {
script {
withDockerRegistry([credentialsId: "docker", url: ""]) {
sh "docker push ${DOCKERHUB_REPO}:${env.BRANCH_NAME}-${SHORT_COMMIT}"
if(env.BRANCH_NAME == 'master') {
sh "docker push ${DOCKERHUB_REPO}:latest"
}
}
}
}
}
} catch (e) {
slackSend (
color: '#FF0000',
message: '`modl-uk-ruby` build has failed on branch `' + env.BRANCH_NAME + '`\n' + \
'more info on ' + env.BUILD_URL,
channel: '#ruby-websites')
throw e
}
}
}