github.com/pf-qiu/concourse/v6@v6.7.3-0.20201207032516-1f455d73275f/atc/exec/step.go (about)

     1  package exec
     2  
     3  import (
     4  	"context"
     5  	"io"
     6  
     7  	"github.com/pf-qiu/concourse/v6/atc"
     8  	"github.com/pf-qiu/concourse/v6/atc/exec/build"
     9  	"github.com/pf-qiu/concourse/v6/vars"
    10  )
    11  
    12  //go:generate counterfeiter . Step
    13  
    14  // A Step is an object that can be executed, whose result (e.g. Success) can be
    15  // collected, and whose dependent resources (e.g. Containers, Volumes) can be
    16  // released, allowing them to expire.
    17  type Step interface {
    18  	// Run executes the step, returning true if the step succeeds, false if it
    19  	// fails, or an error if an error occurs.
    20  	//
    21  	// Run should watch for the given context to be canceled in the event that
    22  	// the build is aborted or the step times out, and be sure to propagate the
    23  	// (context.Context).Err().
    24  	//
    25  	// Steps wrapping other steps should be careful to propagate the context.
    26  	//
    27  	// Steps must be idempotent. Each step is responsible for handling its own
    28  	// idempotency.
    29  	Run(context.Context, RunState) (bool, error)
    30  }
    31  
    32  //go:generate counterfeiter . BuildStepDelegate
    33  
    34  type BuildOutputFilter func(text string) string
    35  
    36  //go:generate counterfeiter . RunState
    37  
    38  type RunState interface {
    39  	vars.Variables
    40  
    41  	NewLocalScope() RunState
    42  	AddLocalVar(name string, val interface{}, redact bool)
    43  
    44  	IterateInterpolatedCreds(vars.TrackedVarsIterator)
    45  	RedactionEnabled() bool
    46  
    47  	ArtifactRepository() *build.Repository
    48  
    49  	Result(atc.PlanID, interface{}) bool
    50  	StoreResult(atc.PlanID, interface{})
    51  
    52  	Run(context.Context, atc.Plan) (bool, error)
    53  
    54  	Parent() RunState
    55  }
    56  
    57  // ExitStatus is the resulting exit code from the process that the step ran.
    58  // Typically if the ExitStatus result is 0, the Success result is true.
    59  type ExitStatus int
    60  
    61  // Privileged is used to indicate whether the given step should run with
    62  // special privileges (i.e. as an administrator user).
    63  type Privileged bool
    64  
    65  type InputHandler func(io.ReadCloser) error
    66  type OutputHandler func(io.Writer) error