From 3a2a5ffa9d77e12960ba0349e1810efb068f0701 Mon Sep 17 00:00:00 2001 From: Vincent Ambo Date: Sun, 19 Dec 2021 19:14:47 +0300 Subject: feat(ops/besadii): Pass Gerrit link to builds as an envvar This makes it possible to annotate builds with a link back to Gerrit. Change-Id: If351785d3b631b96753d41f417ca94bc7a95ac54 Reviewed-on: https://cl.tvl.fyi/c/depot/+/4441 Reviewed-by: grfn Tested-by: BuildkiteCI --- ops/besadii/main.go | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) (limited to 'ops/besadii/main.go') diff --git a/ops/besadii/main.go b/ops/besadii/main.go index e051bb367e..5c9baf6bf5 100644 --- a/ops/besadii/main.go +++ b/ops/besadii/main.go @@ -158,6 +158,11 @@ func loadConfig() (*config, error) { return &cfg, nil } +// linkToChange creates the full link to a change's patchset in Gerrit +func linkToChange(cfg *config, changeId, patchset string) string { + return path.Join(cfg.GerritUrl, "c", cfg.Repository, "+", changeId, patchset) +} + // updateGerrit posts a comment on a Gerrit CL to indicate the current build status. func updateGerrit(cfg *config, review reviewInput, changeId, patchset string) { body, _ := json.Marshal(review) @@ -183,7 +188,7 @@ func updateGerrit(cfg *config, review reviewInput, changeId, patchset string) { respBody, _ := ioutil.ReadAll(resp.Body) fmt.Fprintf(os.Stderr, "received non-success response from Gerrit: %s (%v)", respBody, resp.Status) } else { - fmt.Printf("Added CI status comment on %s/c/%s/+/%s/%s", cfg.GerritUrl, cfg.Repository, changeId, patchset) + fmt.Printf("Added CI status comment on %s", linkToChange(cfg, changeId, patchset)) } } @@ -198,6 +203,7 @@ func triggerBuild(cfg *config, log *syslog.Writer, trigger *buildTrigger) error // to communicate the build status back to Gerrit. headBuild := true if trigger.changeId != "" && trigger.patchset != "" { + env["GERRIT_CHANGE_URL"] = linkToChange(cfg, trigger.changeId, trigger.patchset) env["GERRIT_CHANGE_ID"] = trigger.changeId env["GERRIT_PATCHSET"] = trigger.patchset headBuild = false -- cgit 1.4.1