-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathJenkinsfile
More file actions
70 lines (67 loc) · 2.26 KB
/
Jenkinsfile
File metadata and controls
70 lines (67 loc) · 2.26 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
66
67
68
69
70
pipeline {
environment {
TAG = "v02.3"
IMAGENAME = "ditas/vdc-request-monitor"
}
agent any
stages {
stage('Image creation') {
steps {
echo 'Creating the image...'
sh "docker build -f Dockerfile.testing -t \"${IMAGENAME}:testing\" . --no-cache"
sh "docker build -f Dockerfile.artifact -t \"${IMAGENAME}:${TAG}\" . --no-cache"
echo "Done"
}
}
stage('Testing'){
steps{
sh "docker run --rm ${IMAGENAME}:testing go test -short ./..."
sh "docker rmi ${IMAGENAME}:testing"
}
}
stage('Push image') {
steps {
echo 'Retrieving Docker Hub password from /opt/ditas-docker-hub.passwd...'
script {
password = readFile '/opt/ditas-docker-hub.passwd'
}
echo "Done"
sh "docker login -u ditasgeneric -p ${password}"
echo 'Login to Docker Hub as ditasgeneric...'
sh "docker login -u ditasgeneric -p ${password}"
echo "Done"
echo "Pushing the image ${IMAGENAME}:${TAG}..."
sh "docker push ${IMAGENAME}:${TAG}"
echo "Done"
}
}
stage('Deployment in Staging') {
options {
// Don't need to checkout Git again
skipDefaultCheckout true
}
steps {
sh './jenkins/deploy-staging.sh'
}
}
stage('check if the monitor could be deployed') {
agent any
steps {
sh './jenkins/test.sh'
}
}
stage('Production image creation and push') {
when {
expression {
// only create production image from master branch
branch 'master'
}
}
steps {
// Change the tag from staging to production
sh "docker tag ${IMAGENAME}:${TAG} ${IMAGENAME}:production"
sh "docker push ${IMAGENAME}:production"
}
}
}
}