forked from Sonal0409/DevOpsClassCodes
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
/
Jenkinsfile
40 lines (39 loc) · 1.29 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
pipeline {
agent any
stages {
stage('checkout') {
steps {
git url:'https://github.com/akshu20791/DevOpsClassCodes/', branch: "master"
}
}
stage('Build') {
steps {
sh "mvn clean package"
}
}
stage('Build Image') {
steps {
sh 'docker build -t akshatimg .'
sh 'docker tag akshatimg:latest akshu20791/akshatimgaddbook:latest'
}
}
stage('Docker login') {
steps {
withCredentials([usernamePassword(credentialsId: 'dockercred', passwordVariable: 'PASS', usernameVariable: 'USER')]) {
sh "echo $PASS | docker login -u $USER --password-stdin"
sh 'docker push akshu20791/akshatimgaddbook:latest'
}
}
}
stage('Deploy') {
steps {
script {
def dockerCmd = 'docker run -itd --name My-first-containe211 -p 80:8082 akshu20791/akshatimgaddbook:latest'
sshagent(['sshkeypair']) {
sh "ssh -o StrictHostKeyChecking=no ubuntu@172.31.20.232 ${dockerCmd}"
}
}
}
}
}
}