-
Notifications
You must be signed in to change notification settings - Fork 0
/
Jenkinsfile
32 lines (32 loc) · 1.01 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
node
{
stage('SCM Checkout')
{
git credentialsId: 'ccca2dd6-0b71-4dc4-8296-fac98a9c195e', url: 'https://github.com/raj1831/my-sample-java'
}
stage('Compile package')
{
sh label: 'Build package', script: 'mvn clean package'
}
stage('Build Image in docker')
{
sh label: 'Build Image', script: 'docker build -t raj1831/my-sample-java:1.0.0 .'
}
stage('Push Image'){
withCredentials([string(credentialsId: 'Docker-Pass', variable: 'DockerHubPass')]){
sh label:'Docker login', script: "docker login -u raj1831 -p ${DockerHubPass}"
}
sh label: 'Push Image', script: 'docker push raj1831/my-sample-java:1.0.0'
}
stage('Publish'){
def status = sh label:'', script: 'docker ps -a | grep my-sample-java'
if ( "${status}" -eq "" ){
sh label:'', script: 'docker run -d --name my-sample-java -p 8081:8080 raj1831/my-sample-java:1.0.0'
}
else{
sh label:'', script: 'docker ps -a | grep my-sample-java && docker run -d --name my-sample-java -p 8081:8080 raj1831/my-sample-java:1.0.0'
}
}
fi
}
}