Merge "Add BUILD_USERNAME and BUILD_HOSTNAME"

This commit is contained in:
Treehugger Robot 2019-01-10 21:29:47 +00:00 committed by Gerrit Code Review
commit 20a8856c8f
1 changed files with 18 additions and 0 deletions

View File

@ -18,6 +18,8 @@ import (
"crypto/md5"
"fmt"
"io/ioutil"
"os"
"os/user"
"path/filepath"
"strings"
@ -96,6 +98,22 @@ func runKati(ctx Context, config Config, extraSuffix string, args []string, envF
envFunc(cmd.Environment)
if _, ok := cmd.Environment.Get("BUILD_USERNAME"); !ok {
u, err := user.Current()
if err != nil {
ctx.Println("Failed to get current user")
}
cmd.Environment.Set("BUILD_USERNAME", u.Username)
}
if _, ok := cmd.Environment.Get("BUILD_HOSTNAME"); !ok {
hostname, err := os.Hostname()
if err != nil {
ctx.Println("Failed to read hostname")
}
cmd.Environment.Set("BUILD_HOSTNAME", hostname)
}
cmd.StartOrFatal()
status.KatiReader(ctx.Status.StartTool(), pipe)
cmd.WaitOrFatal()