Skip to content

Commit

Permalink
feat: add environment variable of build cluster name (#451)
Browse files Browse the repository at this point in the history
  • Loading branch information
y-oksaku authored Mar 22, 2023
1 parent 72a19f8 commit e151a1d
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 0 deletions.
1 change: 1 addition & 0 deletions launch.go
Original file line number Diff line number Diff line change
Expand Up @@ -635,6 +635,7 @@ func launch(api screwdriver.API, buildID int, rootDir, emitterPath, metaSpace, s
"SD_STORE_URL": fmt.Sprintf("%s/%s/", storeURL, "v1"),
"SD_UI_URL": fmt.Sprintf("%s/", uiURL),
"SD_UI_BUILD_URL": fmt.Sprintf("%s/pipelines/%s/builds/%s", uiURL, strconv.Itoa(job.PipelineID), strconv.Itoa(buildID)),
"SD_BUILD_CLUSTER_NAME": build.BuildClusterName,
"SD_TOKEN": buildToken,
"SD_CACHE_STRATEGY": cacheStrategy,
"SD_PIPELINE_CACHE_DIR": pipelineCacheDir,
Expand Down
19 changes: 19 additions & 0 deletions launch_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ const (
TestStoreURL = "https://store.screwdriver.cd"
TestUIURL = "https://screwdriver.cd"
TestBuildToken = "foobar"
TestBuildClusterName = "test-build-cluster-name"

TestScmURI = "github.com:123456:master"
TestSHA = "abc123"
Expand Down Expand Up @@ -863,6 +864,7 @@ func TestSetEnv(t *testing.T) {
"SD_UI_URL": "https://screwdriver.cd/",
"SD_UI_BUILD_URL": "https://screwdriver.cd/pipelines/3456/builds/1234",
"SD_TOKEN": "foobar",
"SD_BUILD_CLUSTER_NAME": "",
"SD_SONAR_AUTH_URL": "https://api.screwdriver.cd/v4/coverage/token",
"SD_SONAR_HOST": "https://sonar.screwdriver.cd",
"SD_PIPELINE_CACHE_DIR": "",
Expand Down Expand Up @@ -958,6 +960,23 @@ func TestSetEnv(t *testing.T) {
}
}

// in case of the build cluster exists
api.buildFromID = func(buildID int) (screwdriver.Build, error) {
return screwdriver.Build(FakeBuild{ID: TestBuildID, EventID: TestEventID, JobID: TestJobID, BuildClusterName: TestBuildClusterName, SHA: TestSHA, ParentBuildID: float64(1234)}), nil
}
tests["SD_BUILD_CLUSTER_NAME"] = TestBuildClusterName
TestEnvVars = map[string]interface{}{}
foundEnv = map[string]string{}
err, _, _ = launch(screwdriver.API(api), TestBuildID, TestWorkspace, TestEmitter, TestMetaSpace, TestStoreURL, TestUIURL, TestShellBin, TestBuildTimeout, TestBuildToken, "", "", "", "", false, false, false, 0, 10000)
if err != nil {
t.Fatalf("Unexpected error from launch: %v", err)
}
for k, v := range tests {
if foundEnv[k] != v {
t.Fatalf("foundEnv[%s] = %s, want %s", k, foundEnv[k], v)
}
}

// in case of the pipeline is private
TestPrivateScmRepo := screwdriver.ScmRepo(FakeScmRepo{
Name: "screwdriver-cd/launcher",
Expand Down
1 change: 1 addition & 0 deletions screwdriver/screwdriver.go
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,7 @@ type Build struct {
Stats struct {
QueueEntertime string `json:"queueEnterTime"`
} `json:"stats"`
BuildClusterName string `json:"buildClusterName"`
}

// Coverage is a Coverage object returned when getInfo is called
Expand Down
1 change: 1 addition & 0 deletions screwdriver/screwdriver_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,7 @@ func TestBuildFromID(t *testing.T) {
}{
QueueEntertime: "2020-05-01T20:15:31.508Z",
},
BuildClusterName: "test-build-cluster-name",
},
statusCode: 200,
err: nil,
Expand Down

0 comments on commit e151a1d

Please sign in to comment.