-
Notifications
You must be signed in to change notification settings - Fork 0
/
Jenkinsfile1.txt
54 lines (49 loc) · 2.19 KB
/
Jenkinsfile1.txt
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
pipeline{
agent any
environment{
dockerTag = getLatestCommitId()
devIp = '3.84.50.84'
}
stages {
stage('Docker - Build & Push'){
steps{
sh "docker build . -t 0352730247/node-app:${dockerTag} "
withCredentials([string(credentialsId: 'docker-hub', variable: 'dockerHubPwd')]) {
sh "docker login -u 0352730247 -p ${dockerHubPwd}"
}
sh "docker push 0352730247/node-app:${dockerTag}"
}
}
stage('Dev Deploy'){
steps {
sh "chmod +x changeTag.sh"
sh "./changeTag.sh ${dockerTag}"
sshagent(['loclpt-keypair-virginia']) {
script{
sh "ssh -o StrictHostKeyChecking=no ubuntu@${devIp} docker rm -f node-app"
withCredentials([string(credentialsId: 'docker-hub', variable: 'dockerHubPwd')]) {
sh "ssh ubuntu@${devIp} docker login -u 0352730247 -p ${dockerHubPwd}"
}
def runCmd = "docker run -d -p 8080:8080 --name=nodeapp 0352730247/node-app:${dockerTag}"
sh "ssh -o StrictHostKeyChecking=no ubuntu@${devIp} ${runCmd}"
// sh 'ssh -o StrictHostKeyChecking=no [email protected] rm -rf /home/tanloc/jenkins'
// sh 'ssh -o StrictHostKeyChecking=no [email protected] mkdir /home/tanloc/jenkins'
// sh 'scp -o StrictHostKeyChecking=no index.html [email protected]:/home/tanloc/jenkins'
}
// sh "scp -o StrictHostKeyChecking=no services.yml node-app-pod.yml ubuntu@${devIp}:/home/ubuntu/"
// script{
// try {
// sh "ssh ubuntu@${devIp} kubectl apply -f ."
// } catch {
// sh "ssh ubuntu@${devIp} kubectl create -f ."
// }
// }
}
}
}
}
}
def getLatestCommitId(){
def commitId = sh returnStdout: true, script: 'git rev-parse HEAD'
return commitId
}