Skip to content

Commit 4ada7e7

Browse files
Merge pull request #101 from KeisukeYamashita/support-regional-cloudbuild
Support regional (=private pool) Cloud Build
2 parents 807b0b1 + 2c1c267 commit 4ada7e7

File tree

2 files changed

+18
-4
lines changed

2 files changed

+18
-4
lines changed

ci.go

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,10 @@ import (
88
"strings"
99
)
1010

11+
const (
12+
defaultCloudBuildRegion = "global"
13+
)
14+
1115
// CI represents a common information obtained from all CI platforms
1216
type CI struct {
1317
PR PullRequest
@@ -150,8 +154,15 @@ func githubActions() (ci CI, err error) {
150154
func cloudbuild() (ci CI, err error) {
151155
ci.PR.Number = 0
152156
ci.PR.Revision = os.Getenv("COMMIT_SHA")
157+
158+
region := os.Getenv("REGION")
159+
if region == "" {
160+
region = defaultCloudBuildRegion
161+
}
162+
153163
ci.URL = fmt.Sprintf(
154-
"https://console.cloud.google.com/cloud-build/builds/%s?project=%s",
164+
"https://console.cloud.google.com/cloud-build/builds;region=%s/%s?project=%s",
165+
region,
155166
os.Getenv("BUILD_ID"),
156167
os.Getenv("PROJECT_ID"),
157168
)

ci_test.go

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -766,6 +766,7 @@ func TestCloudBuild(t *testing.T) {
766766
"BUILD_ID",
767767
"PROJECT_ID",
768768
"_PR_NUMBER",
769+
"REGION",
769770
}
770771
saveEnvs := make(map[string]string)
771772
for _, key := range envs {
@@ -790,13 +791,14 @@ func TestCloudBuild(t *testing.T) {
790791
os.Setenv("BUILD_ID", "build-id")
791792
os.Setenv("PROJECT_ID", "gcp-project-id")
792793
os.Setenv("_PR_NUMBER", "123")
794+
os.Setenv("REGION", "asia-northeast1")
793795
},
794796
ci: CI{
795797
PR: PullRequest{
796798
Revision: "abcdefg",
797799
Number: 123,
798800
},
799-
URL: "https://console.cloud.google.com/cloud-build/builds/build-id?project=gcp-project-id",
801+
URL: "https://console.cloud.google.com/cloud-build/builds;region=asia-northeast1/build-id?project=gcp-project-id",
800802
},
801803
ok: true,
802804
},
@@ -806,13 +808,14 @@ func TestCloudBuild(t *testing.T) {
806808
os.Setenv("BUILD_ID", "build-id")
807809
os.Setenv("PROJECT_ID", "gcp-project-id")
808810
os.Setenv("_PR_NUMBER", "")
811+
os.Setenv("REGION", "")
809812
},
810813
ci: CI{
811814
PR: PullRequest{
812815
Revision: "",
813816
Number: 0,
814817
},
815-
URL: "https://console.cloud.google.com/cloud-build/builds/build-id?project=gcp-project-id",
818+
URL: "https://console.cloud.google.com/cloud-build/builds;region=global/build-id?project=gcp-project-id",
816819
},
817820
ok: true,
818821
},
@@ -828,7 +831,7 @@ func TestCloudBuild(t *testing.T) {
828831
Revision: "",
829832
Number: 0,
830833
},
831-
URL: "https://console.cloud.google.com/cloud-build/builds/build-id?project=gcp-project-id",
834+
URL: "https://console.cloud.google.com/cloud-build/builds;region=global/build-id?project=gcp-project-id",
832835
},
833836
ok: false,
834837
},

0 commit comments

Comments
 (0)