-
Notifications
You must be signed in to change notification settings - Fork 0
/
Jenkinsfile
42 lines (38 loc) · 1.53 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
pipeline {
agent any
stages {
stage('Build') {
steps {
sh 'docker image build --tag gcr.io/api-project-367056975125/$PROJECT_NAME:$(git rev-parse --short HEAD) .'
}
}
stage('Push') {
steps {
sh 'cat $GCP_SERVICE_ACCOUNT | docker login -u _json_key --password-stdin https://gcr.io'
sh '''docker image tag gcr.io/api-project-367056975125/$PROJECT_NAME:$(git rev-parse --short HEAD) gcr.io/api-project-367056975125/$PROJECT_NAME:latest
docker image push gcr.io/api-project-367056975125/$PROJECT_NAME:$(git rev-parse --short HEAD)
docker image push gcr.io/api-project-367056975125/$PROJECT_NAME:latest'''
}
}
stage('Deploy') {
when { branch 'master' }
steps {
sh 'docker image pull google/cloud-sdk'
sh '''docker container run \\
-e "GCP_JSON=$(cat $GCP_SERVICE_ACCOUNT)" \\
-e "PROJECT_NAME=$PROJECT_NAME" \\
-e "IMAGE_TAG=$(git rev-parse --short HEAD)" \\
google/cloud-sdk \\
bash -c "printenv GCP_JSON > /gcp_service_account.json \\
&& echo "$PROJECT_NAME=gcr.io/api-project-367056975125/$PROJECT_NAME:\\${IMAGE_TAG}" \\
&& gcloud auth activate-service-account --key-file /gcp_service_account.json \\
&& gcloud container clusters get-credentials dbz-arterion --zone us-east1-b \\
&& kubectl set image deployment/$PROJECT_NAME $PROJECT_NAME=gcr.io/api-project-367056975125/$PROJECT_NAME:\\$IMAGE_TAG --record"'''
}
}
}
environment {
GCP_SERVICE_ACCOUNT = credentials('gcp-service-account')
PROJECT_NAME = 'brendancboyle-website'
}
}