forked from akshu20791/php-project
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathJenkinsfile2
More file actions
55 lines (52 loc) · 1.8 KB
/
Jenkinsfile2
File metadata and controls
55 lines (52 loc) · 1.8 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
// here we are using parameters where in the deployyment will only happen when we approve it
pipeline {
agent any
parameters {
choice(
name: 'executeJob',
choices: ['Yes', 'No'],
description: 'Do you want to execute the job?'
)
}
stages {
stage('git cloned') {
steps {
git url:'https://github.com/akshu20791/php-project/', branch: "master"
}
}
stage('Build docker image') {
steps {
script {
sh 'docker build -t akshu20791/amdocsapril:v1 .'
sh 'docker images'
}
}
}
stage('Docker login') {
when {
expression { params.executeJob == 'Yes' }
}
steps {
withCredentials([usernamePassword(credentialsId: 'dockerhub-pwd', passwordVariable: 'PASS', usernameVariable: 'USER')]) {
sh "echo $PASS | docker login -u $USER --password-stdin"
sh 'docker push akshu20791/amdocsapril:v1'
}
}
}
stage('Deploy') {
when {
expression { params.executeJob == 'Yes' }
}
steps {
script {
def dockerrm = 'sudo docker rm -f My-first-containe221 || true'
def dockerCmd = 'sudo docker run -itd --name My-first-containe2211 -p 8083:80 akshu20791/amdocsapril:v1'
sshagent(['sshkeypair']) {
sh "ssh -o StrictHostKeyChecking=no ubuntu@172.31.30.45 ${dockerrm}"
sh "ssh -o StrictHostKeyChecking=no ubuntu@172.31.30.45 ${dockerCmd}"
}
}
}
}
}
}