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
26 lines (26 loc) · 1.05 KB
/
Jenkinsfile
File metadata and controls
26 lines (26 loc) · 1.05 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
pipeline {
agent any
environment {
GCR_CREDENTIALS_ID = 'jenkins-secret' // The ID you provided in Jenkins credentials
IMAGE_NAME = 't3-image'
GCR_URL = 'europe-west1-docker.pkg.dev/lbg-mea-20/repo-t3'
}
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}:${BUILD_NUMBER} ."
// Push the Docker image to GCR
sh "docker push ${GCR_URL}/${IMAGE_NAME}:${BUILD_NUMBER}"
}
}
}
}
}