forked from felipemeriga/DevOps-Example
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathJenkinsfile
More file actions
49 lines (36 loc) · 1.46 KB
/
Jenkinsfile
File metadata and controls
49 lines (36 loc) · 1.46 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
node {
// reference to maven
// ** NOTE: This 'maven-3.5.2' Maven tool must be configured in the Jenkins Global Configuration.
def mvnHome = tool 'maven-3.5.2'
// holds reference to docker image
def dockerImage
// ip address of the docker private repository(nexus)
def dockerImageTag = "devopsexample${env.BUILD_NUMBER}"
stage('Clone Repo') { // for display purposes
// Get some code from a GitHub repository
git 'https://github.com/felipemeriga/DevOps-Example.git'
// Get the Maven tool.
// ** NOTE: This 'maven-3.5.2' Maven tool must be configured
// ** in the global configuration.
mvnHome = tool 'maven-3.5.2'
}
stage('Build Project') {
// build project via maven
sh "'${mvnHome}/bin/mvn' clean install"
}
stage('Build Docker Image') {
// build docker image
dockerImage = docker.build("devopsexample:${env.BUILD_NUMBER}")
}
stage('Deploy Docker Image'){
// deploy docker image to nexus
echo "Docker Image Tag Name: ${dockerImageTag}"
sh "docker stop devopsexample"
sh "docker rm devopsexample"
sh "docker run --name devopsexample -d -p 2222:2222 devopsexample:${env.BUILD_NUMBER}"
// docker.withRegistry('https://registry.hub.docker.com', 'docker-hub-credentials') {
// dockerImage.push("${env.BUILD_NUMBER}")
// dockerImage.push("latest")
// }
}
}