forked from vikash-kumar01/Kubernetes_Project
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Jenkinsfile_vboxvm
41 lines (38 loc) · 1.92 KB
/
Jenkinsfile_vboxvm
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
node {
stage('Git Checkout'){
git 'https://github.com/rajesh1218/Kubernetes_Project.git'
}
stage('Send Dockerfile to Docker-host') {
sshagent(['docker-server']) {
sh 'ssh -o StrictHostKeyChecking=no -l vagrant 192.168.56.116 uname -a'
sh 'scp -o StrictHostKeyChecking=no /var/jenkins_home/workspace/pipeline-cicd/* [email protected]:/home/vagrant/'
}
}
stage('Docker Build') {
sshagent(['docker-server']) {
sh 'ssh -o StrictHostKeyChecking=no [email protected] docker build -t $JOB_NAME:v1.$BUILD_ID .'
sh 'ssh -o StrictHostKeyChecking=no [email protected] docker tag $JOB_NAME:v1.$BUILD_ID rajeshjallu/$JOB_NAME:latest'
}
}
stage('Docker push to docker hub') {
sshagent(['docker-server']) {
withCredentials([string(credentialsId: 'dockerhub_pass', variable: 'dockerhub_pass')]) {
sh 'ssh -o StrictHostKeyChecking=no [email protected] docker login -u rajeshjallu -p ${dockerhub_pass}'
sh 'ssh -o StrictHostKeyChecking=no [email protected] docker push rajeshjallu/$JOB_NAME:latest'
sh 'ssh -o StrictHostKeyChecking=no [email protected] docker rmi $JOB_NAME:v1.$BUILD_ID rajeshjallu/$JOB_NAME:latest'
}
}
}
stage('Send files to k8s-host') {
sshagent(['k8s-server']) {
sh 'ssh -o StrictHostKeyChecking=no -l vagrant 192.168.29.239 uname -a'
sh 'scp -o StrictHostKeyChecking=no /var/jenkins_home/workspace/pipeline-cicd/* [email protected]:/home/vagrant/'
}
}
stage('publish in k8s') {
sshagent(['ansible-server']) {
sh 'ssh -o StrictHostKeyChecking=no -l vagrant 192.168.56.115 uname -a'
sh 'ssh -o StrictHostKeyChecking=no -l vagrant 192.168.56.115 ansible-playbook ansible.yml'
}
}
}