forked from vikash-kumar01/Jenkins-Docker-Project
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathJenkinsfile
41 lines (36 loc) · 1.56 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
pipeline {
agent any
stages {
stage("git login"){
steps{
git 'https://github.com/vjdbj/CICD.git'
}
}
stage("docker build"){
steps{
sh 'docker image build -t $JOB_NAME:v1.$BUILD_ID .'
sh 'docker image tag $JOB_NAME:v1.$BUILD_ID vishalramakant/$JOB_NAME:v1.$BUILD_ID'
sh 'docker image tag $JOB_NAME:v1.$BUILD_ID vishalramakant/$JOB_NAME:latest'
}
}
stage("pushing images to dockerhub"){
steps{
withCredentials([string(credentialsId: 'dockerhub-password', variable: 'passwd')]) {
sh "docker login -u vishalramakant -p ${passwd}"
sh 'docker image push vishalramakant/$JOB_NAME:v1.$BUILD_ID'
sh 'docker image push vishalramakant/$JOB_NAME:latest'
sh 'docker image rm $JOB_NAME:v1.$BUILD_ID vishalramakant/$JOB_NAME:v1.$BUILD_ID vishalramakant/$JOB_NAME:latest'
}
}
}
stage("docker container deployment"){
steps{
sshagent(['webapp']) {
sh 'ssh -o StrictHostKeyChecking=no [email protected] docker rm -f jj-container'
sh 'ssh -o StrictHostKeyChecking=no [email protected] docker rmi -f vishalramakant/demo-1'
sh 'ssh -o StrictHostKeyChecking=no [email protected] docker run -itd --name jj-container -p 9000:80 vishalramakant/demo-1'
}
}
}
}
}