-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathjenkinsfile
45 lines (45 loc) · 1.23 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
pipeline {
environment {
registry = "interviewdot/cicd-k8s-demo"
registryCredential = 'docker-hub-credentials'
dockerImage = ''
}
agent any
stages {
stage('Compile') {
steps {
git 'https://github.com/net-vinothkumar/cicd-k8s-demo.git'
script{
def mvnHome = tool name: 'MAVEN_HOME', type: 'maven'
sh "${mvnHome}/bin/mvn package"
}
}
}
stage('Building Docker Image') {
steps{
script {
dockerImage = docker.build registry + ":$BUILD_NUMBER"
}
}
}
stage('Push Image To Docker Hub') {
steps{
script {
/* Finally, we'll push the image with two tags:
* First, the incremental build number from Jenkins
* Second, the 'latest' tag.
* Pushing multiple tags is cheap, as all the layers are reused. */
docker.withRegistry('https://registry.hub.docker.com', 'docker-hub-credentials') {
dockerImage.push("${env.BUILD_NUMBER}")
dockerImage.push("latest")
}
}
}
}
stage('Deploy to Kubernetes'){
steps{
sh 'kubectl apply -f deployment.yml'
}
}
}
}