本文整理汇总了Golang中github.com/wercker/wercker/core.Step类的典型用法代码示例。如果您正苦于以下问题:Golang Step类的具体用法?Golang Step怎么用?Golang Step使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Step类的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: newMetricStepPayload
func newMetricStepPayload(step core.Step) *metricStepPayload {
return &metricStepPayload{
Owner: step.Owner(),
Name: step.Name(),
Version: step.Version(),
FullName: fmt.Sprintf("%s/%s", step.Owner(), step.Name()),
UniqueName: formatUniqueStepName(step),
}
}
示例2: RecoverInteractive
//RecoverInteractive restarts the box with a terminal attached
func (b *DockerBox) RecoverInteractive(cwd string, pipeline core.Pipeline, step core.Step) error {
// TODO(termie): maybe move the container manipulation outside of here?
client := b.client
container, err := b.Restart()
if err != nil {
b.logger.Panicln("box restart failed")
return err
}
env := []string{}
env = append(env, pipeline.Env().Export()...)
env = append(env, pipeline.Env().Hidden.Export()...)
env = append(env, step.Env().Export()...)
env = append(env, fmt.Sprintf("cd %s", cwd))
cmd := []string{b.cmd}
return client.AttachInteractive(container.ID, cmd, env)
}
示例3: executePipeline
func executePipeline(cmdCtx context.Context, options *core.PipelineOptions, dockerOptions *dockerlocal.DockerOptions, getter pipelineGetter) (*RunnerShared, error) {
// Boilerplate
soft := NewSoftExit(options.GlobalOptions)
logger := util.RootLogger().WithField("Logger", "Main")
e, err := core.EmitterFromContext(cmdCtx)
if err != nil {
return nil, err
}
f := &util.Formatter{options.GlobalOptions.ShowColors}
// Set up the runner
r, err := NewRunner(cmdCtx, options, dockerOptions, getter)
if err != nil {
return nil, err
}
// Main timer
mainTimer := util.NewTimer()
timer := util.NewTimer()
// These will be emitted at the end of the execution, we're going to be
// pessimistic and report that we failed, unless overridden at the end of the
// execution.
fullPipelineFinisher := r.StartFullPipeline(options)
pipelineArgs := &core.FullPipelineFinishedArgs{}
defer fullPipelineFinisher.Finish(pipelineArgs)
buildFinisher := r.StartBuild(options)
buildFinishedArgs := &core.BuildFinishedArgs{Box: nil, Result: "failed"}
defer buildFinisher.Finish(buildFinishedArgs)
// Debug information
DumpOptions(options)
// Do some sanity checks before starting
err = dockerlocal.RequireDockerEndpoint(dockerOptions)
if err != nil {
return nil, soft.Exit(err)
}
// Start copying code
logger.Println(f.Info("Executing pipeline"))
timer.Reset()
_, err = r.EnsureCode()
if err != nil {
e.Emit(core.Logs, &core.LogsArgs{
Stream: "stderr",
Logs: err.Error() + "\n",
})
return nil, soft.Exit(err)
}
err = r.CleanupOldBuilds()
if err != nil {
e.Emit(core.Logs, &core.LogsArgs{
Stream: "stderr",
Logs: err.Error() + "\n",
})
}
if options.Verbose {
logger.Printf(f.Success("Copied working dir", timer.String()))
}
// Setup environment is still a fairly special step, it needs
// to start our boxes and get everything set up
logger.Println(f.Info("Running step", "setup environment"))
timer.Reset()
shared, err := r.SetupEnvironment(cmdCtx)
if shared.box != nil {
if options.ShouldRemove {
defer shared.box.Clean()
}
defer shared.box.Stop()
}
if err != nil {
logger.Errorln(f.Fail("Step failed", "setup environment", timer.String()))
e.Emit(core.Logs, &core.LogsArgs{
Stream: "stderr",
Logs: err.Error() + "\n",
})
return nil, soft.Exit(err)
}
if options.Verbose {
logger.Printf(f.Success("Step passed", "setup environment", timer.String()))
}
// Expand our context object
box := shared.box
buildFinishedArgs.Box = box
pipeline := shared.pipeline
repoName := pipeline.DockerRepo()
tag := pipeline.DockerTag()
message := pipeline.DockerMessage()
shouldStore := options.ShouldArtifacts
// TODO(termie): hack for now, probably can be made into a naive class
var storeStep core.Step
if shouldStore {
storeStep = &core.ExternalStep{
//.........这里部分代码省略.........
示例4: RunStep
// RunStep runs a step and tosses error if it fails
func (p *Runner) RunStep(shared *RunnerShared, step core.Step, order int) (*StepResult, error) {
finisher := p.StartStep(shared, step, order)
sr := &StepResult{
Success: false,
Artifact: nil,
Message: "",
ExitCode: 1,
}
defer finisher.Finish(sr)
if step.ShouldSyncEnv() {
err := shared.pipeline.SyncEnvironment(shared.sessionCtx, shared.sess)
if err != nil {
// If an error occured, just log and ignore it
p.logger.WithField("Error", err).Warn("Unable to sync environment")
}
}
step.InitEnv(shared.pipeline.Env())
p.logger.Debugln("Step Environment")
for _, pair := range step.Env().Ordered() {
p.logger.Debugln(" ", pair[0], pair[1])
}
exit, err := step.Execute(shared.sessionCtx, shared.sess)
if exit != 0 {
sr.ExitCode = exit
if p.options.AttachOnError {
shared.box.RecoverInteractive(
p.options.SourcePath(),
shared.pipeline,
step,
)
}
} else if err == nil {
sr.Success = true
sr.ExitCode = 0
}
// Grab the message
var message bytes.Buffer
messageErr := step.CollectFile(shared.containerID, step.ReportPath(), "message.txt", &message)
if messageErr != nil {
if messageErr != util.ErrEmptyTarball {
return sr, messageErr
}
}
sr.Message = message.String()
// This is the error from the step.Execute above
if err != nil {
if sr.Message == "" {
sr.Message = err.Error()
}
return sr, err
}
// Grab artifacts if we want them
if p.options.ShouldArtifacts {
artifact, err := step.CollectArtifact(shared.containerID)
if err != nil {
return sr, err
}
if artifact != nil {
artificer := dockerlocal.NewArtificer(p.options, p.dockerOptions)
err = artificer.Upload(artifact)
if err != nil {
return sr, err
}
}
sr.Artifact = artifact
}
if !sr.Success {
return sr, fmt.Errorf("Step failed with exit code: %d", sr.ExitCode)
}
return sr, nil
}
示例5: formatUniqueStepName
func formatUniqueStepName(step core.Step) string {
return fmt.Sprintf("%s/%[email protected]%s", step.Owner(), step.Name(), step.Version())
}