-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathJenkinsfile
73 lines (62 loc) · 2.07 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
node() {
def app
def appRepoName="IG-Trading-Microservices"
def repoURI="068478564052.dkr.ecr.eu-west-2.amazonaws.com/ig-trading-app"
def containersActive
try {
stage('Checkout'){
checkout scm
echo "build id - ${env.BUILD_ID}"
echo 'env.PATH=' + env.PATH
}
echo "out of checkout"
stage('build'){
echo "removing existing images first"
echo "images removed now onto building a new image"
app = docker-compose.build("${appRepoName}")
echo "docker build succeeded!!!"
}
echo "out of build stage"
stage('Docker push'){
/* First, the incremental build number from Jenkins
* Second, the 'latest' tag.
* Pushing multiple tags is cheap, as all the layers are reused. */
/*docker.withRegistry("https://${repoURI}", 'ecr:eu-west-2:068478564052') {
echo "ecr registration success!!!"
app.push("${env.BUILD_ID}")*/
}
}
stage('Docker run'){
/* First remove the existing containers but set the command to true so that even if
there are no containers running or existing the error returned by docker rm command
doesnt stop the pipeline process from running further */
sh (
script:
"""\
docker ps -qa | xargs docker rm -f || true\
""",
)
echo "in docker run now with docker image = ${app}"
echo "this is the build id = ${env.BUILD_ID}"
sh (
/*script: "docker run -d --name predictainer-\"${env.BUILD_ID}\" -p 80:80 \"${repoURI}\"/\"${appRepoName}\":\"${env.BUILD_ID}\"",*/
script: "docker-compose.yml up",
)
echo "now that the image is running in container we should remove the image"
sh (
script: "docker rmi \"${repoURI}\"/\"${appRepoName}\":\"${env.BUILD_ID}\"",
)
echo "container created"
echo "THE END-------------------------"
}
}
catch (err) {
currentBuild.result = "FAILURE"
mail body: "project build error is here: ${env.BUILD_URL}" ,
from: '[email protected]',
replyTo: '[email protected]',
subject: 'project build failed',
to: '[email protected]'
throw err
}
}