-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathJenkinsfile
48 lines (46 loc) · 1.83 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
pipeline {
agent any
tools {
maven 'Maven 3.6.2'
jdk 'jdk8'
}
stages {
stage ("Package") {
steps {
sh 'mvn clean package'
}
}
stage ("Build Docker Image") {
steps {
sh 'docker build --rm -t books-api .'
}
}
stage ("Start mysql") {
steps {
sh 'docker-compose up -d'
}
}
stage ("Deploy Docker Image to test locally") {
steps {
sh 'docker run -d --rm --name=books-api --net=my-network -p 9090:9090 -e "SPRING_PROFILES_ACTIVE=docker" books-api'
}
}
stage('E2E Tests'){
steps{
checkout([$class: 'GitSCM', branches: [[name: '*/master']], doGenerateSubmoduleConfigurations: false, extensions: [[$class: 'CloneOption', depth: 0, noTags: true, reference: '', shallow: false, timeout: 60], [$class: 'SubmoduleOption', disableSubmodules: false, parentCredentials: false, recursiveSubmodules: true, reference: '', timeout: 60, trackingSubmodules: true], [$class: 'RelativeTargetDirectory', relativeTargetDir: 'E2E'],[$class: 'CheckoutOption', timeout: 60]], submoduleCfg: [], userRemoteConfigs: [[url: 'https://github.com/dhaneshkhot/books-api-rest-assured.git']]])
dir("E2E"){
sh 'ls -ltr'
sh 'mvn test -Dtest="com.example.tests.books.BooksEndToEndTests" -Denv=docker -DdbUsername=root -DdbPassword=password'
}
}
}
}
post {
always {
sh 'docker stop books-api'
// sh 'docker rm books-api' // not needed here as rm is included in run command, line #25
sh 'docker rmi books-api:latest -f'
sh 'docker-compose down'
}
}
}