-
Notifications
You must be signed in to change notification settings - Fork 391
/
Jenkinsfile
59 lines (48 loc) · 1.81 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
node {
// reference to maven
// ** NOTE: This 'maven-3.6.1' Maven tool must be configured in the Jenkins Global Configuration.
def mvnHome = tool 'maven-3.8.5'
// holds reference to docker image
def dockerImage
// ip address of the docker private repository(nexus)
def dockerRepoUrl = "localhost:8083"
def dockerImageName = "hello-world-java"
def dockerImageTag = "${dockerRepoUrl}/${dockerImageName}:${env.BUILD_NUMBER}"
stage('Clone Repo') { // for display purposes
// Get some code from a GitHub repository
git 'https://github.com/dstar55/docker-hello-world-spring-boot.git'
// Get the Maven tool.
// ** NOTE: This 'maven-3.6.1' Maven tool must be configured
// ** in the global configuration.
mvnHome = tool 'maven-3.8.5'
}
stage('Build Project') {
// build project via maven
sh "'${mvnHome}/bin/mvn' -Dmaven.test.failure.ignore clean package"
}
stage('Publish Tests Results'){
parallel(
publishJunitTestsResultsToJenkins: {
echo "Publish junit Tests Results"
junit '**/target/surefire-reports/TEST-*.xml'
archive 'target/*.jar'
},
publishJunitTestsResultsToSonar: {
echo "This is branch b"
})
}
stage('Build Docker Image') {
// build docker image
sh "whoami"
//sh "ls -all /var/run/docker.sock"
sh "mv ./target/hello*.jar ./data"
dockerImage = docker.build("hello-world-java")
}
stage('Deploy Docker Image'){
// deploy docker image to nexus
echo "Docker Image Tag Name: ${dockerImageTag}"
sh "docker login -u admin -p admin123 ${dockerRepoUrl}"
sh "docker tag ${dockerImageName} ${dockerImageTag}"
sh "docker push ${dockerImageTag}"
}
}