diff --git a/pkg/build/agent.tpl b/pkg/build/agent.tpl index cd10605..6421df3 100644 --- a/pkg/build/agent.tpl +++ b/pkg/build/agent.tpl @@ -115,7 +115,7 @@ func register (host string) { time.Sleep(waitDelay) continue } - + register_extra = os.Getenv("ECHO_APP_ID") + {{.CommitID}} // 注册,直接将元信息放在 ws 地址中 v := url.Values{} v.Set("hostname", ps.hostname) diff --git a/pkg/build/build.go b/pkg/build/build.go index 683a00f..e0795e2 100644 --- a/pkg/build/build.go +++ b/pkg/build/build.go @@ -50,6 +50,7 @@ type Build struct { Pkgs map[string]*Package GlobalCoverVarImportPath string GlobalCoverVarImportPathDir string + CommitID string } // NewBuild creates a Build struct diff --git a/pkg/build/goenv.go b/pkg/build/goenv.go index 5368654..c723086 100644 --- a/pkg/build/goenv.go +++ b/pkg/build/goenv.go @@ -64,6 +64,13 @@ func (b *Build) readProjectMetaInfo() { // get GlobalCoverVarImportPath b.GlobalCoverVarImportPath = path.Join(b.ImportPath, TmpFolderName(b.CurModProjectDir)) log.Donef("project meta information parsed") + cmd := exec.Command("git", "describe", "--abbrev=8", "--always") + output, err := cmd.Output() + if err != nil { + log.Errorf("git describe Error:", err) + } else { + b.CommitID = string(output) + } } // displayProjectMetaInfo prints basic infomation of this project to stdout