Skip to content

Commit e151a1d

Browse files
authored
feat: add environment variable of build cluster name (#451)
1 parent 72a19f8 commit e151a1d

File tree

4 files changed

+22
-0
lines changed

4 files changed

+22
-0
lines changed

launch.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -635,6 +635,7 @@ func launch(api screwdriver.API, buildID int, rootDir, emitterPath, metaSpace, s
635635
"SD_STORE_URL": fmt.Sprintf("%s/%s/", storeURL, "v1"),
636636
"SD_UI_URL": fmt.Sprintf("%s/", uiURL),
637637
"SD_UI_BUILD_URL": fmt.Sprintf("%s/pipelines/%s/builds/%s", uiURL, strconv.Itoa(job.PipelineID), strconv.Itoa(buildID)),
638+
"SD_BUILD_CLUSTER_NAME": build.BuildClusterName,
638639
"SD_TOKEN": buildToken,
639640
"SD_CACHE_STRATEGY": cacheStrategy,
640641
"SD_PIPELINE_CACHE_DIR": pipelineCacheDir,

launch_test.go

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ const (
4040
TestStoreURL = "https://store.screwdriver.cd"
4141
TestUIURL = "https://screwdriver.cd"
4242
TestBuildToken = "foobar"
43+
TestBuildClusterName = "test-build-cluster-name"
4344

4445
TestScmURI = "github.com:123456:master"
4546
TestSHA = "abc123"
@@ -863,6 +864,7 @@ func TestSetEnv(t *testing.T) {
863864
"SD_UI_URL": "https://screwdriver.cd/",
864865
"SD_UI_BUILD_URL": "https://screwdriver.cd/pipelines/3456/builds/1234",
865866
"SD_TOKEN": "foobar",
867+
"SD_BUILD_CLUSTER_NAME": "",
866868
"SD_SONAR_AUTH_URL": "https://api.screwdriver.cd/v4/coverage/token",
867869
"SD_SONAR_HOST": "https://sonar.screwdriver.cd",
868870
"SD_PIPELINE_CACHE_DIR": "",
@@ -958,6 +960,23 @@ func TestSetEnv(t *testing.T) {
958960
}
959961
}
960962

963+
// in case of the build cluster exists
964+
api.buildFromID = func(buildID int) (screwdriver.Build, error) {
965+
return screwdriver.Build(FakeBuild{ID: TestBuildID, EventID: TestEventID, JobID: TestJobID, BuildClusterName: TestBuildClusterName, SHA: TestSHA, ParentBuildID: float64(1234)}), nil
966+
}
967+
tests["SD_BUILD_CLUSTER_NAME"] = TestBuildClusterName
968+
TestEnvVars = map[string]interface{}{}
969+
foundEnv = map[string]string{}
970+
err, _, _ = launch(screwdriver.API(api), TestBuildID, TestWorkspace, TestEmitter, TestMetaSpace, TestStoreURL, TestUIURL, TestShellBin, TestBuildTimeout, TestBuildToken, "", "", "", "", false, false, false, 0, 10000)
971+
if err != nil {
972+
t.Fatalf("Unexpected error from launch: %v", err)
973+
}
974+
for k, v := range tests {
975+
if foundEnv[k] != v {
976+
t.Fatalf("foundEnv[%s] = %s, want %s", k, foundEnv[k], v)
977+
}
978+
}
979+
961980
// in case of the pipeline is private
962981
TestPrivateScmRepo := screwdriver.ScmRepo(FakeScmRepo{
963982
Name: "screwdriver-cd/launcher",

screwdriver/screwdriver.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -184,6 +184,7 @@ type Build struct {
184184
Stats struct {
185185
QueueEntertime string `json:"queueEnterTime"`
186186
} `json:"stats"`
187+
BuildClusterName string `json:"buildClusterName"`
187188
}
188189

189190
// Coverage is a Coverage object returned when getInfo is called

screwdriver/screwdriver_test.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,7 @@ func TestBuildFromID(t *testing.T) {
145145
}{
146146
QueueEntertime: "2020-05-01T20:15:31.508Z",
147147
},
148+
BuildClusterName: "test-build-cluster-name",
148149
},
149150
statusCode: 200,
150151
err: nil,

0 commit comments

Comments
 (0)