-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathJenkinsfile
74 lines (74 loc) · 2.47 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
74
pipeline {
environment {
registry = "yaronpr/yaronpetclinic"
registryCredential = "dockerhub"
}
agent {
docker {
image 'yaronpr/mavenwithdocker:3.6.1-alpine'
args '-v /var/run/docker.sock:/var/run/docker.sock'
}
}
options {
skipStagesAfterUnstable()
}
stages {
stage ('Download JCenter Settings') {
steps {
sh 'curl -L "https://bintray.com/repo/downloadMavenRepoSettingsFile/downloadSettings?repoPath=%2Fbintray%2Fjcenter" -o settings.xml'
}
}
stage ('Clone Source') {
steps {
git branch: 'master', url: 'https://github.com/spring-projects/spring-petclinic.git'
}
}
stage('Compile Source') {
steps {
sh 'mvn -DskipTests -s settings.xml clean package'
}
post {
always {
archiveArtifacts artifacts: 'target/*.jar', fingerprint: true
}
}
}
stage('Run Tests') {
steps {
sh 'mvn -Dmaven.test.failure.ignore=false -s settings.xml test'
}
post {
always {
junit 'target/surefire-reports/*.xml'
}
}
}
stage('Extract Jar') {
steps {
sh 'cd target && jar xvf *.jar '
}
}
stage('Docker Build') {
steps {
echo 'download Dockerfile'
sh 'curl -L "https://raw.githubusercontent.com/yaprigal/SpringPetClinic/master/Dockerfile" -o Dockerfile'
echo 'docker builld start'
sh 'docker build -t $registry:$BUILD_NUMBER .'
}
}
stage('Docker Push') {
steps {
echo 'docker push start'
withDockerRegistry([ credentialsId: "$registryCredential", url: "" ]) {
sh 'docker push $registry:$BUILD_NUMBER'
sh 'docker push $registry:latest'
}
}
}
stage('Remove Unused Docker Image') {
steps {
sh 'docker rmi $registry:$BUILD_NUMBER'
}
}
}
}