Skip to content

Commit 717e9a3

Browse files
authored
Merge pull request #149 from buildkite/triarius/job_in_build_url
2 parents 1d20a81 + af7f585 commit 717e9a3

2 files changed

Lines changed: 15 additions & 0 deletions

File tree

api/api.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ const (
1212
UUIDLabel = "buildkite.com/job-uuid"
1313
TagLabel = "buildkite.com/job-tag"
1414
BuildURLAnnotation = "buildkite.com/build-url"
15+
JobURLAnnotation = "buildkite.com/job-url"
1516
DefaultNamespace = "default"
1617
DefaultAgentImage = "ghcr.io/buildkite/agent-k8s:latest"
1718
)

internal/scheduler/scheduler.go

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import (
44
"context"
55
"encoding/json"
66
"fmt"
7+
"net/url"
78
"strconv"
89
"strings"
910

@@ -176,6 +177,8 @@ func (w *jobWrapper) Build() (*batchv1.Job, error) {
176177
w.k8sPlugin.Metadata.Labels[api.UUIDLabel] = w.job.Uuid
177178
w.k8sPlugin.Metadata.Labels[api.TagLabel] = api.TagToLabel(w.job.Tag)
178179
w.k8sPlugin.Metadata.Annotations[api.BuildURLAnnotation] = w.envMap["BUILDKITE_BUILD_URL"]
180+
w.annotateWithJobURL()
181+
179182
kjob.Labels = w.k8sPlugin.Metadata.Labels
180183
kjob.Spec.Template.Labels = w.k8sPlugin.Metadata.Labels
181184
kjob.Annotations = w.k8sPlugin.Metadata.Annotations
@@ -432,6 +435,17 @@ func (w *jobWrapper) BuildFailureJob(err error) (*batchv1.Job, error) {
432435
return w.Build()
433436
}
434437

438+
func (w *jobWrapper) annotateWithJobURL() {
439+
buildURL := w.envMap["BUILDKITE_BUILD_URL"]
440+
u, err := url.Parse(buildURL)
441+
if err != nil {
442+
w.logger.Warn("could not parse BuildURL when annotating with JobURL", zap.String("buildURL", buildURL))
443+
return
444+
}
445+
u.Fragment = w.job.Uuid
446+
w.k8sPlugin.Metadata.Annotations[api.JobURLAnnotation] = u.String()
447+
}
448+
435449
func kjobName(job *monitor.Job) string {
436450
return fmt.Sprintf("buildkite-%s", job.Uuid)
437451
}

0 commit comments

Comments
 (0)