-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathJenkinsfile
More file actions
60 lines (55 loc) · 1.92 KB
/
Jenkinsfile
File metadata and controls
60 lines (55 loc) · 1.92 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
56
57
58
59
60
pipeline {
agent any
stages {
stage('Build Docker Image') {
steps {
sh 'docker build -t sbhusal123/django-app:latest .'
}
}
stage('Push Docker Image To Registry') {
steps {
// username and password secret to be set
// credentialsId: dockerhub_credentials
withCredentials(
[usernamePassword(
credentialsId: 'dockerhub_credentials',
usernameVariable: 'DOCKERHUB_USERNAME',
passwordVariable: 'DOCKERHUB_PASSWORD'
)]
) {
sh 'echo "$DOCKERHUB_PASSWORD" | docker login -u "$DOCKERHUB_USERNAME" --password-stdin'
sh 'docker push sbhusal123/django-app:latest'
}
}
}
stage('Rollout Deployment') {
steps {
// secret text credentials to be set
withCredentials([
string(credentialsId: 'ssh_user', variable: 'SSH_USER'),
string(credentialsId: 'ssh_host', variable: 'SSH_HOST'),
string(credentialsId: 'git_repo_url', variable: 'REPO_URL')
]) {
sshagent(['kube_ssh_key']) {
sshagent(['kube_ssh_key']) {
// note the indentation must be as below for EOF delimiter
sh """
ssh -o StrictHostKeyChecking=no ${SSH_USER}@${SSH_HOST} <<EOF
if [ -d django-kubernetes-deployment ]; then
cd django-kubernetes-deployment
git pull
else
git clone ${REPO_URL} django-kubernetes-deployment
cd django-kubernetes-deployment
fi
make run
make rollout_deployment
EOF
"""
}
}
}
}
}
}
}