forked from shivaaws69/Wisdom-School-Spring-Project
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcloudbuild-commit-id.yaml
More file actions
54 lines (46 loc) · 1.49 KB
/
cloudbuild-commit-id.yaml
File metadata and controls
54 lines (46 loc) · 1.49 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
substitutions:
_REPO: "asia-docker.pkg.dev/$_PROJECT_ID/school/sch"
steps:
# Step 1: Check out the repository (Cloud Build clones the source automatically)
- name: gcr.io/cloud-builders/git
entrypoint: "bash"
args:
- "-c"
- |
echo "Source code is already cloned by Cloud Build."
git checkout $(git rev-parse --short=6 HEAD) # Explicitly check out the commit
# Step 2: Set up JDK (for Maven)
- name: gcr.io/cloud-builders/mvn
args:
- clean
- package
# Step 3: Authenticate to Google Cloud
- name: gcr.io/cloud-builders/gcloud
args:
- auth
- configure-docker
- asia-docker.pkg.dev
# Step 4: Get the first 6 characters of the commit SHA and convert to lowercase
- name: gcr.io/cloud-builders/git
entrypoint: "bash"
args:
- "-c"
- |
COMMIT_SHA=$(git rev-parse --short=6 HEAD)
_COMMIT_SHA_LOWER=$(echo $COMMIT_SHA | tr '[:upper:]' '[:lower:]') # Convert to lowercase
echo "Commit SHA (first 6 chars, lowercase): $_COMMIT_SHA_LOWER" > /workspace/commit_id.txt
# Step 5: Build the Docker image and tag it with the lowercase commit SHA
- name: gcr.io/cloud-builders/docker
args:
- build
- "-t"
- "$_REPO:$_COMMIT_SHA_LOWER"
- "."
# Step 6: Push the Docker image with the lowercase commit SHA tag
- name: gcr.io/cloud-builders/docker
args:
- push
- "$_REPO:$_COMMIT_SHA_LOWER"
logsBucket: gs://school-build-logs
options:
logging: GCS_ONLY