forked from ukhsa-collaboration/foodscanner_compute
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathprod-Jenkinsfile
82 lines (77 loc) · 2.21 KB
/
prod-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
String branchName = "master"
String gitCredentials = "phe-jenkins-ssh"
String repoUrl = "[email protected]:publichealthengland/foodscanner_compute.git"
pipeline
{
options
{
buildDiscarder(logRotator(numToKeepStr: '3'))
}
agent any
environment
{
VERSION = 'latest'
PROJECT = 'swaps-cache-builder-prod'
IMAGE = 'swaps-cache-builder-prod:latest'
// DOCKERFILEPATH = "--file=docker/Dockerfile ."
ECRURL = 'https://116851924324.dkr.ecr.eu-west-2.amazonaws.com/swaps-cache-builder-prod'
ECRCRED = 'ecr:eu-west-2:phe-prod'
}
stages
{
stage('Git Checkout')
{
steps
{
script
{
checkout([$class: 'GitSCM',
branches: [[name: branchName ]],
doGenerateSubmoduleConfigurations: false,
extensions: [],
submoduleCfg: [],
userRemoteConfigs: [[
url: repoUrl,
credentialsId: gitCredentials
]]
])
}
}
}
stage('Docker build')
{
steps
{
script
{
// Build the docker image using a Dockerfile
docker.build("$IMAGE")
}
}
}
stage('Docker push')
{
steps
{
script
{
// login to ECR - for now it seems that that the ECR Jenkins plugin is not performing the login as expected. I hope it will in the future.
sh("eval \$(aws ecr get-login --no-include-email | sed 's|https://||')")
// Push the Docker image to ECR
docker.withRegistry(ECRURL, ECRCRED)
{
docker.image(IMAGE).push()
}
}
}
}
}
post
{
always
{
// make sure that the Docker image is removed
sh "docker rmi $IMAGE | true"
}
}
}