-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathJenkinsfile
More file actions
54 lines (47 loc) · 1.3 KB
/
Copy pathJenkinsfile
File metadata and controls
54 lines (47 loc) · 1.3 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
pipeline {
agent any
environment {
DOCKER_IMAGE = 'elvdevops/ansible-webapp'
DOCKER_USERNAME = ('docker-username')
DOCKER_PASSWORD = ('docker-password')
KUBE_NAMESPACE = 'elvdevops-webapp'
}
stages {
stage('Checkout Code') {
steps {
checkout scm
}
}
stage('Docker Login') {
steps {
script {
sh """
echo $DOCKER_PASSWORD | docker login -u $DOCKER_USERNAME --password-stdin
"""
}
}
}
stage('Build Docker Image') {
steps {
sh 'docker build -t $DOCKER_IMAGE:latest .'
}
}
stage('Push Docker Image') {
steps {
withDockerRegistry([credentialsId: 'docker-hub-credentials']) {
sh 'docker push $DOCKER_IMAGE:latest'
}
}
}
stage('Run Ansible Playbook') {
steps {
sh 'ansible-playbook -i inventory deploy.yml'
}
}
stage('Deploy to Kubernetes') {
steps {
sh 'kubectl apply -f k8s/deployment.yaml -n $KUBE_NAMESPACE'
}
}
}
}