-
Notifications
You must be signed in to change notification settings - Fork 0
/
Jenkinsfile
64 lines (58 loc) · 1.67 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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
pipeline
{
agent any
environment
{
IMAGE_NAME="backend"
INSTANCE="150.136.53.239"
GIT_USERNAME="vipinachar"
GIT_APITOKEN="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"
DOCKER_USERNAME="vipinachar1998"
}
stages
{
stage("Git Clone")
{
steps
{
git "https://${GIT_USERNAME}:${GIT_APITOKEN}@github.com/vipinachar/Jenkins.git"
}
}
stage("Build Docker Image")
{
steps
{
sh 'docker build -t ${DOCKER_USERNAME}/${IMAGE_NAME}:${BUILD_NUMBER} .'
}
}
stage("Docker Login")
{
steps
{
withCredentials([string(credentialsId: 'docker_hub_password', variable: 'docker_hub_password')])
{
sh 'docker login -u ${DOCKER_USERNAME} -p ${docker_hub_password}'
}
}
}
stage("Push the image to Dockerhub")
{
steps
{
sh 'docker push ${DOCKER_USERNAME}/${IMAGE_NAME}:${BUILD_NUMBER}'
}
}
stage("Deploy the application on k8s")
{
steps
{
sshagent(['oci_password_v1'])
{
sh "sed -i 's/image_build_number/${BUILD_NUMBER}/' Deploy.yml"
sh 'scp Deploy.yml opc@${INSTANCE}:.'
sh 'ssh -o StrictHostKeyChecking=no opc@${INSTANCE} kubectl apply -f Deploy.yml'
}
}
}
}
}