forked from QACTrainers/LBG-Python-API-Base
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathJenkinsfile
More file actions
75 lines (38 loc) · 1.6 KB
/
Jenkinsfile
File metadata and controls
75 lines (38 loc) · 1.6 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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
pipeline {
agent any
environment {
GCR_CREDENTIALS_ID = 'lbg-mea-15'
IMAGE_NAME = 'test-image-7'
GCR_URL = 'gcr.io/hughprojectday'
PROJECT_ID = 'hughprojectday'
CLUSTER_NAME = 'demo-cluster'
LOCATION = 'europe-west2-c'
CREDENTIALS_ID = 'PROJ_DAY'
}
stages {
stage('Build and Push to GCR') {
steps {
script {
// Authenticate with Google Cloud
withCredentials([file(credentialsId: GCR_CREDENTIALS_ID, variable: 'GOOGLE_APPLICATION_CREDENTIALS')]) {
sh 'gcloud auth activate-service-account --key-file=$GOOGLE_APPLICATION_CREDENTIALS'
}
// Configure Docker to use gcloud as a credential helper
sh 'gcloud auth configure-docker --quiet'
// Build the Docker image
sh "docker build -t ${GCR_URL}/${IMAGE_NAME}:latest ."
// Push the Docker image to GCR
sh "docker push ${GCR_URL}/${IMAGE_NAME}:latest"
}
}
}
stage('Deploy to GKE') {
steps {
script {
// Deploy to GKE using Jenkins Kubernetes Engine Plugin
step([$class: 'KubernetesEngineBuilder', projectId: env.PROJECT_ID, clusterName: env.CLUSTER_NAME, location: env.LOCATION, manifestPattern: 'kubernetes/deployment.yaml', credentialsId: env.CREDENTIALS_ID, verifyDeployments: true])
}
}
}
}
}