Commit 329a1fef authored by Kamil Trzciński's avatar Kamil Trzciński 🔴

Remove buildMessage from Build and push it to BuildLog

parent db2743d1
......@@ -28,7 +28,6 @@ type Build struct {
BuildStarted time.Time `json:"build_started"`
BuildFinished time.Time `json:"build_finished"`
BuildDuration time.Duration `json:"build_duration"`
BuildMessage string `json:"build_message"`
BuildAbort chan os.Signal `json:"-" yaml:"-"`
BuildDir string `json:"-" yaml:"-"`
Hostname string `json:"-" yaml:"-"`
......@@ -143,9 +142,8 @@ func (b *Build) StartBuild(buildDir string) {
b.BuildDir = buildDir
}
func (b *Build) FinishBuild(buildState BuildState, buildMessage string, args ...interface{}) {
func (b *Build) FinishBuild(buildState BuildState) {
b.BuildState = buildState
b.BuildMessage = "\n" + fmt.Sprintf(buildMessage, args...)
b.BuildFinished = time.Now()
b.BuildDuration = b.BuildFinished.Sub(b.BuildStarted)
}
......@@ -178,10 +176,6 @@ func (b *Build) SendBuildLog() {
var buildTrace string
buildTrace = b.BuildLog()
if b.BuildMessage != "" {
buildTrace = buildTrace + b.BuildMessage
}
for {
if UpdateBuild(*b.Runner, b.ID, b.BuildState, buildTrace) != UpdateFailed {
break
......@@ -194,7 +188,7 @@ func (b *Build) SendBuildLog() {
func (b *Build) Run(globalConfig *Config) error {
executor := NewExecutor(b.Runner.Executor)
if executor == nil {
b.FinishBuild(Failed, "Executor not found: %v", b.Runner.Executor)
b.WriteString("Executor not found: " + b.Runner.Executor)
b.SendBuildLog()
return errors.New("executor not found")
}
......
......@@ -55,7 +55,11 @@ func (e *AbstractExecutor) ReadTrace(pipe *io.PipeReader) {
}
if e.Build.BuildLogLen() > traceOutputLimit {
output := fmt.Sprintf("\nBuild log exceeded limit of %v bytes.", traceOutputLimit)
output := fmt.Sprintf("\n%sBuild log exceeded limit of %v bytes.%s\n",
helpers.ANSI_BOLD_RED,
traceOutputLimit,
helpers.ANSI_RESET,
)
e.Build.WriteString(output)
traceStopped = true
break
......@@ -80,7 +84,7 @@ func (e *AbstractExecutor) PushTrace(config common.RunnerConfig, canceled chan b
for {
select {
case <-time.After(common.UpdateInterval * time.Second):
// check if build log changed
// check if build log changed
buildTraceLen := e.Build.BuildLogLen()
if buildTraceLen == lastSentTrace && time.Since(lastSentTime) > common.ForceTraceSentInterval {
e.Debugln("updateBuildLog", "Nothing to send.")
......@@ -128,10 +132,23 @@ func (e *AbstractExecutor) Println(args ...interface{}) {
log.Println(args...)
}
func (e *AbstractExecutor) Infoln(args ...interface{}) {
if e.Build != nil {
e.Build.WriteString(helpers.ANSI_BOLD_GREEN + fmt.Sprintln(args...) + helpers.ANSI_RESET)
}
if len(args) == 0 {
return
}
args = append([]interface{}{e.Config.ShortDescription(), e.Build.ID}, args...)
log.Println(args...)
}
func (e *AbstractExecutor) Warningln(args ...interface{}) {
// write to log file
if e.Build != nil {
e.Build.WriteString("WARNING:" + fmt.Sprintln(args...))
e.Build.WriteString(helpers.ANSI_BOLD_YELLOW + "WARNING:" + fmt.Sprintln(args...) + helpers.ANSI_RESET)
}
args = append([]interface{}{e.Config.ShortDescription(), e.Build.ID}, args...)
......@@ -141,7 +158,7 @@ func (e *AbstractExecutor) Warningln(args ...interface{}) {
func (e *AbstractExecutor) Errorln(args ...interface{}) {
// write to log file
if e.Build != nil {
e.Build.WriteString("ERROR: " + fmt.Sprintln(args...))
e.Build.WriteString(helpers.ANSI_BOLD_RED + "ERROR: " + fmt.Sprintln(args...) + helpers.ANSI_RESET)
}
args = append([]interface{}{e.Config.ShortDescription(), e.Build.ID}, args...)
......@@ -209,7 +226,7 @@ func (e *AbstractExecutor) Prepare(globalConfig *common.Config, config *common.R
return err
}
e.Println(fmt.Sprintf("%s %s (%s)", common.NAME, common.VERSION, common.REVISION))
e.Infoln(fmt.Sprintf("%s %s (%s)", common.NAME, common.VERSION, common.REVISION))
err = e.verifyOptions()
if err != nil {
......@@ -237,31 +254,32 @@ func (e *AbstractExecutor) Wait() error {
log.Debugln(e.Config.ShortDescription(), e.Build.ID, "Waiting for signals...")
select {
case <-e.BuildCanceled:
log.Println(e.Config.ShortDescription(), e.Build.ID, "Build got canceled.")
e.Build.FinishBuild(common.Failed, "Build got canceled")
e.Warningln("Build got canceled.")
e.Build.FinishBuild(common.Failed)
case <-time.After(time.Duration(buildTimeout) * time.Second):
log.Println(e.Config.ShortDescription(), e.Build.ID, "Build timedout.")
e.Build.FinishBuild(common.Failed, "CI Timeout. Execution took longer then %d seconds", buildTimeout)
e.Errorln("CI Timeout. Execution took longer then %d seconds.", buildTimeout)
e.Build.FinishBuild(common.Failed)
case signal := <-e.Build.BuildAbort:
log.Println(e.Config.ShortDescription(), e.Build.ID, "Build got aborted", signal)
e.Build.FinishBuild(common.Failed, "Build got aborted: %v", signal)
e.Errorln("Build got aborted: %v.", signal)
e.Build.FinishBuild(common.Failed)
case err := <-e.BuildFinish:
if err != nil {
return err
}
log.Println(e.Config.ShortDescription(), e.Build.ID, "Build succeeded.")
e.Build.FinishBuild(common.Success, "Build succeeded.")
e.Infoln("Build succeeded.")
e.Build.FinishBuild(common.Success)
}
return nil
}
func (e *AbstractExecutor) Finish(err error) {
if err != nil {
e.Build.FinishBuild(common.Failed, "Build failed with %v", err)
e.Errorln("Build failed with %v.", err)
e.Build.FinishBuild(common.Failed)
}
e.Debugln("Build took", e.Build.BuildDuration)
......
......@@ -19,8 +19,9 @@ func (s *SSHExecutor) Prepare(globalConfig *common.Config, config *common.Runner
return err
}
s.Println("Using SSH executor...")
if s.ShellScript.PassFile {
return errors.New("Parallels doesn't support shells that require script file")
return errors.New("SSH doesn't support shells that require script file")
}
return nil
}
......
......@@ -21,7 +21,7 @@ func (b *BashShell) GetName() string {
}
func (b *BashShell) echoColored(w io.Writer, text string) {
coloredText := helpers.ANSI_BOLD_GREEN + text + helpers.ANSI_BOLD_WHITE
coloredText := helpers.ANSI_BOLD_GREEN + text + helpers.ANSI_RESET
io.WriteString(w, "echo " + helpers.ShellEscape(coloredText) + "\n")
}
......@@ -81,6 +81,7 @@ func (b *BashShell) GenerateScript(info common.ShellScriptInfo) (*common.ShellSc
}
io.WriteString(w, "\n")
b.echoColored(w, "")
if build.AllowGitFetch {
b.writeFetchCmd(w, build, helpers.ShellEscape(projectDir), helpers.ShellEscape(gitDir))
} else {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment