forked from networknuts/jenkins-docker-project
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Jenkinsfile
47 lines (47 loc) · 1.76 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
pipeline {
agent any
parameters {
string(name: 'DOCKER_TAG', description: 'Enter the tag for the image', defaultValue: 'latest')
}
stages {
stage('Git Checkout') {
steps {
// This stage is to get the Dockerfile
git branch: 'main',
url: 'https://github.com/networknuts/jenkins-docker-kubernetes-project.git'
}
}
stage('Build Docker Image') {
steps {
script {
// Make sure that Docker is installed and configured before reaching here
def dockerImage = docker.build("docker.io/aryansr/kube-app:${params.DOCKER_TAG}","-f Dockerfile .")
docker.withRegistry('','docker-creds') {
dockerImage.push("${params.DOCKER_TAG}")
}
}
}
}
stage('Scan Docker Image') {
steps {
sh "docker run -v /var/run/docker.sock:/var/run/docker.sock -v $HOME/Library/Caches:/root/.cache/ aquasec/trivy:0.51.1 image docker.io/aryansr/kube-app:${params.DOCKER_TAG}"
}
}
stage("Update Tag in deployment.yml") {
steps {
script {
sh "sed -i 's|image:.*|image: docker.io/aryansr/kube-app:${params.DOCKER_TAG}|g' deployment.yaml"
}
}
}
stage("Deploy on Kubernetes") {
steps {
script {
withKubeConfig([credentialsId: 'kubernetes-creds', serverUrl: 'https://networknuts-dns-zm1c7fde.hcp.centralindia.azmk8s.io']) {
sh "kubectl apply -f deployment.yaml"
}
}
}
}
}
}