forked from acloudpotato/GKE-Automation-using-jenkins
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Jenkinsfile
46 lines (46 loc) · 1.59 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
pipeline {
agent any
environment {
PROJECT_ID = 'kubernetes-project-340710'
CLUSTER_NAME = 'gke-cluster'
LOCATION = 'asia-south1-a'
CREDENTIALS_ID = 'jenkins-gke'
}
stages {
stage("Checkout code") {
steps {
checkout([$class: 'GitSCM', branches: [[name: '*/master']], extensions: [], userRemoteConfigs: [[url: 'https://github.com/omkarsuperb/test-jenkins.git']]])
}
}
stage("Build image") {
steps {
script {
Img = docker.build(
"gcr.io/kubernetes-project-340710/new",
"-f Dockerfile ."
)
}
}
}
stage("Push image") {
steps {
script {
withDockerRegistry([credentialsId: "gcr:gcr", url: "https://gcr.io"]) {
sh "docker push gcr.io/kubernetes-project-340710/new"
}
}
}
}
stage('Creating Artifact'){
steps{
archiveArtifacts artifacts: '**', followSymlinks: false
}
}
stage('Deploy to GKE') {
steps{
sh "sed -i 's/hello:latest/hello:${env.BUILD_ID}/g' deployment.yaml"
step([$class: 'KubernetesEngineBuilder', projectId: env.PROJECT_ID, clusterName: env.CLUSTER_NAME, location: env.LOCATION, manifestPattern: 'deployment.yaml', credentialsId: env.CREDENTIALS_ID, verifyDeployments: true])
}
}
}
}