forked from DevSecOpsG/DevOps-Example
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathJenkinsfile
More file actions
57 lines (46 loc) · 1.86 KB
/
Jenkinsfile
File metadata and controls
57 lines (46 loc) · 1.86 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
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'
def javaHome = tool 'JDK8' // Replace 'JDK8' with your configured JDK name
// 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/ja983/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'
javaHome = tool 'JDK8'
}
stage('Build Project') {
// build project via maven
withEnv(["JAVA_HOME=${javaHome}", "PATH+=${javaHome}/bin"]) {
sh "'${mvnHome}/bin/mvn' clean install"
}
}
stage('Build Docker Image') {
// build docker image
dockerImage = docker.build("devopsexample:${env.BUILD_NUMBER}")
}
stage('Deploy Docker Image and login'){
echo "Docker Image Tag Name: ${dockerImageTag}"
sh "docker images"
sh "docker login -u vickeyyvickey -p Hello@123" // put PWD
}
stage('Docker push'){
// Extract the image ID for the devopsexample:${BUILD_NUMBER} image
def imageId = sh(script: "docker images --format '{{.ID}}' devopsexample:${env.BUILD_NUMBER}", returnStdout: true).trim()
def repoName = "vickeyyvickey/myapplication"
// Tag the image
sh "docker tag ${imageId} ${repoName}"
// Push to Docker Hub
sh "docker push ${repoName}"
}
stage('Run Application') {
sh "docker run -d -p 2222:2222 vickeyyvickey/myapplication"
}
}