aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFranck Cuny <franck@fcuny.net>2022-06-09 14:08:23 -0700
committerFranck Cuny <franck@fcuny.net>2022-06-09 14:10:08 -0700
commit0af5ba2275016d2998f78008c873baee8eb6f1d1 (patch)
treee0925d0f94300eb5e0f6ef795b3b39efe6cb36c1
parentfeat(buildkite): configure the post-command hook (diff)
downloadinfra-0af5ba2275016d2998f78008c873baee8eb6f1d1.tar.gz
feat(gerrit-hook): propagate gerrit information in the environment
The buildKite agents need this information in order to vote after a build. Change-Id: If03ba51d55f4d1155c6b7fdadace3b4643480258 Reviewed-on: https://cl.fcuny.net/c/world/+/342 Reviewed-by: Franck Cuny <franck@fcuny.net>
-rw-r--r--tools/gerrit-hook/buildkite.go20
1 files changed, 17 insertions, 3 deletions
diff --git a/tools/gerrit-hook/buildkite.go b/tools/gerrit-hook/buildkite.go
index 35ad31c..07d2cfd 100644
--- a/tools/gerrit-hook/buildkite.go
+++ b/tools/gerrit-hook/buildkite.go
@@ -9,13 +9,15 @@ import (
"log/syslog"
"net/http"
"os"
+ "strings"
"time"
)
// https://buildkite.com/docs/apis/rest-api/builds#create-a-Build
type Build struct {
- Commit string `json:"commit"`
- Branch string `json:"branch"`
+ Commit string `json:"commit"`
+ Branch string `json:"branch"`
+ Env map[string]string `json:"env"`
}
type buildResponse struct {
@@ -23,9 +25,21 @@ type buildResponse struct {
}
func triggerBuild(cfg *config, log *syslog.Writer, trigger *buildTrigger) error {
+ env := make(map[string]string)
+ branch := trigger.ref
+
+ if trigger.changeId != "" && trigger.patchset != "" {
+ env["GERRIT_CHANGE_ID"] = trigger.changeId
+ env["GERRIT_CHANGE_URL"] = trigger.changeUrl
+ env["GERRIT_PATCHSET"] = trigger.patchset
+
+ branch = fmt.Sprintf("cl/%v", strings.Split(trigger.ref, "/")[3])
+ }
+
b := Build{
Commit: trigger.commit,
- Branch: trigger.ref,
+ Branch: branch,
+ Env: env,
}
body, _ := json.Marshal(b)