Merge pull request #1713 from bradrydzewski/master

write exit code to logs
This commit is contained in:
Brad Rydzewski 2016-07-13 11:04:31 -07:00 committed by GitHub
commit 4d6f711b7a
2 changed files with 47 additions and 1 deletions

View file

@ -2,8 +2,10 @@ package build
import ( import (
"bufio" "bufio"
"strconv"
"time" "time"
"github.com/Sirupsen/logrus"
"github.com/drone/drone/yaml" "github.com/drone/drone/yaml"
) )
@ -48,6 +50,12 @@ func (p *Pipeline) Next() <-chan error {
// Exec executes the current step. // Exec executes the current step.
func (p *Pipeline) Exec() { func (p *Pipeline) Exec() {
go func() { go func() {
defer func() {
if r := recover(); r != nil {
logrus.Errorln("recover executing build step", r)
}
}()
err := p.exec(p.head.Container) err := p.exec(p.head.Container)
if err != nil { if err != nil {
p.err = err p.err = err
@ -119,6 +127,11 @@ func (p *Pipeline) step() {
// close closes open channels and signals the pipeline is done. // close closes open channels and signals the pipeline is done.
func (p *Pipeline) close(err error) { func (p *Pipeline) close(err error) {
go func() { go func() {
defer func() {
if r := recover(); r != nil {
logrus.Errorln("recover closing the pipeline", r)
}
}()
p.done <- err p.done <- err
}() }()
} }
@ -131,6 +144,12 @@ func (p *Pipeline) exec(c *yaml.Container) error {
p.containers = append(p.containers, name) p.containers = append(p.containers, name)
go func() { go func() {
defer func() {
if r := recover(); r != nil {
logrus.Errorln("recover writing build output", r)
}
}()
rc, rerr := p.engine.ContainerLogs(name) rc, rerr := p.engine.ContainerLogs(name)
if rerr != nil { if rerr != nil {
return return
@ -165,5 +184,19 @@ func (p *Pipeline) exec(c *yaml.Container) error {
} else if state.ExitCode != 0 { } else if state.ExitCode != 0 {
return &ExitError{c.Name, state.ExitCode} return &ExitError{c.Name, state.ExitCode}
} }
go func() {
defer func() {
if r := recover(); r != nil {
logrus.Errorln("recover writing exit code to output", r)
}
}()
p.pipe <- &Line{
Proc: c.Name,
Type: ExitCodeLine,
Out: strconv.Itoa(state.ExitCode),
}
}()
return nil return nil
} }

View file

@ -2,6 +2,14 @@ package build
import "fmt" import "fmt"
const (
StdoutLine int = iota
StderrLine
ExitCodeLine
MetadataLine
ProgressLine
)
// Line is a line of console output. // Line is a line of console output.
type Line struct { type Line struct {
Proc string `json:"proc,omitempty"` Proc string `json:"proc,omitempty"`
@ -12,7 +20,12 @@ type Line struct {
} }
func (l *Line) String() string { func (l *Line) String() string {
return fmt.Sprintf("[%s:L%v:%vs] %s", l.Proc, l.Pos, l.Time, l.Out) switch l.Type {
case ExitCodeLine:
return fmt.Sprintf("[%s] exit code %s", l.Proc, l.Out)
default:
return fmt.Sprintf("[%s:L%v:%vs] %s", l.Proc, l.Pos, l.Time, l.Out)
}
} }
// State defines the state of the container. // State defines the state of the container.