-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathJenkinsfile
More file actions
94 lines (86 loc) · 3.18 KB
/
Jenkinsfile
File metadata and controls
94 lines (86 loc) · 3.18 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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
pipeline {
agent none
stages {
stage('Build - test') {
agent {
dockerfile {
filename 'Dockerfile.build'
}
}
steps {
// Build
sh 'gradle clean build -x test'
// Archive the artifact to be accessible from the Artifacts tab into the Blue Ocean interface, just to have it handy
archiveArtifacts 'build/libs/*.jar'
// Test
sh 'gradle test'
}
// Save the reports always
post {
always {
// Record the jUnit test
junit 'build/test-results/test/*.xml'
}
}
}
stage('Staging image creation') {
agent any
options {
skipDefaultCheckout true
}
steps {
// The Dockerfile.artifact copies the code into the image and run the jar generation.
echo 'Creating the image...'
// This will search for a Dockerfile.artifact in the working directory and build the image to the local repository
sh "docker build -t \"ditas/vdc-resolution-engine:staging\" -f Dockerfile.artifact ."
echo "Done"
// Get the password from a file. This reads the file from the host, not the container. Slaves already have the password in there.
echo 'Retrieving Docker Hub password from /opt/ditas-docker-hub.passwd...'
script {
password = readFile '/opt/ditas-docker-hub.passwd'
}
echo "Done"
echo 'Login to Docker Hub as ditasgeneric...'
sh "docker login -u ditasgeneric -p ${password}"
echo "Done"
echo "Pushing the image ditas/vdc-resolution-engine:staging"
sh "docker push ditas/vdc-resolution-engine:staging"
echo "Done "
}
}
stage('Deployment in Staging') {
agent any
options {
// Don't need to checkout Git again
skipDefaultCheckout true
}
steps {
// Deploy to Staging environment calling the deployment script
sh './jenkins/deploy/deploy-staging.sh'
}
}
stage('Dredd API validation') {
agent any
steps {
sh './jenkins/dredd/run-api-test.sh'
}
}
stage('Production image creation') {
agent any
steps {
// Change the tag from staging to production
sh "docker tag ditas/vdc-resolution-engine:staging ditas/vdc-resolution-engine:production"
sh "docker push ditas/vdc-resolution-engine:production"
}
}
stage('Deployment in Production') {
agent any
steps {
// Production environment: 178.22.69.83
// Private key for ssh: /opt/keypairs/ditas-testbed-keypair.pem
// Call the deployment script
sh './jenkins/deploy/deploy-production.sh'
}
}
}
}