Commit 2f97a752 authored by Kamil Trzciński's avatar Kamil Trzciński 🔴

Make debug log more readable by printing scripts and build log as text instead of array of bytes

parent 882e6d1c
......@@ -4,6 +4,7 @@ import (
"bytes"
"errors"
"fmt"
"gitlab.com/gitlab-org/gitlab-ci-multi-runner/helpers"
"net/url"
"os"
"path/filepath"
......@@ -22,16 +23,16 @@ const (
)
type Build struct {
GetBuildResponse
BuildState BuildState `json:"build_state"`
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:"-"`
BuildDir string
Hostname string
Runner *RunnerConfig `json:"runner"`
GetBuildResponse `yaml:",inline"`
BuildState BuildState `json:"build_state"`
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:"-"`
Runner *RunnerConfig `json:"runner"`
// Unique ID for all running builds (globally)
GlobalID int `json:"global_id"`
......@@ -42,7 +43,7 @@ type Build struct {
// Unique ID for all running builds on this runner and this project
ProjectRunnerID int `json:"project_runner_id"`
buildLog bytes.Buffer `json:"-"`
buildLog bytes.Buffer
buildLogLock sync.RWMutex
}
......@@ -198,3 +199,7 @@ func (b *Build) Run() error {
}
return err
}
func (b *Build) String() string {
return helpers.ToYAML(b)
}
......@@ -7,6 +7,7 @@ import (
"os"
"time"
"fmt"
"github.com/BurntSushi/toml"
log "github.com/Sirupsen/logrus"
"gitlab.com/gitlab-org/gitlab-ci-multi-runner/helpers"
......@@ -72,6 +73,10 @@ func (c *RunnerConfig) UniqueID() string {
return c.URL + c.Token
}
func (c *RunnerConfig) String() string {
return fmt.Sprintf("%v url=%v token=%v executor=%v", c.Name, c.URL, c.Token, c.Executor)
}
func NewConfig() *Config {
return &Config{
BaseConfig: BaseConfig{
......
......@@ -3,6 +3,7 @@ package common
import (
"fmt"
log "github.com/Sirupsen/logrus"
"gitlab.com/gitlab-org/gitlab-ci-multi-runner/helpers"
"strings"
)
......@@ -42,6 +43,10 @@ func (s *ShellScript) GetScriptBytes() []byte {
return []byte(s.Script)
}
func (s *ShellScript) String() string {
return helpers.ToYAML(s)
}
type Shell interface {
GetName() string
GenerateScript(build *Build, shellType ShellType) (*ShellScript, error)
......
......@@ -236,6 +236,8 @@ func (e *AbstractExecutor) Finish(err error) {
e.Debugln("Build log updater finished.")
}
e.Debugln("Build log: ", e.Build.BuildLog())
// Send final build state to server
e.Build.SendBuildLog()
e.Println("Build finished.")
......
package helpers
import (
"bufio"
"bytes"
"encoding/json"
"github.com/BurntSushi/toml"
"gopkg.in/yaml.v1"
)
func ToJson(src interface{}) string {
data, err := json.Marshal(src)
if err == nil {
return string(data)
} else {
return ""
}
}
func ToYAML(src interface{}) string {
data, err := yaml.Marshal(src)
if err == nil {
return string(data)
} else {
return ""
}
}
func ToTOML(src interface{}) string {
var data bytes.Buffer
buffer := bufio.NewWriter(&data)
if err := toml.NewEncoder(buffer).Encode(src); err != nil {
return ""
}
if err := buffer.Flush(); err != nil {
return ""
}
return data.String()
}
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