Help us shape the future of Go! Take the 2026 Go Developer Survey

task

package
v0.11.34 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 21, 2026 License: GPL-3.0 Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrRequiredInputMissing = errors.New("missing required input")

Functions

This section is empty.

Types

type Artifact

type Artifact struct {
	// Name is the key under which the artifacts will be stored
	//
	// Currently this is unused
	Name string `mapstructure:"name" yaml:"name,omitempty" json:"name,omitempty"`
	// Path is the glob like pattern to the
	// source of the file(s) to store as an output
	Path string `mapstructure:"path" yaml:"path,omitempty" json:"path,omitempty"`
	// Type is the artifact type
	// valid values are `file`|`dotenv`
	Type ArtifactType `mapstructure:"type" yaml:"type" json:"type" jsonschema:"enum=dotenv,enum=file,enum=env,default=dotenv"`
}

Artifact holds the information about the artifact to produce for the specific task.

NB: it is run at the end of the task so any after commands that mutate the output files/dotenv file will essentially overwrite anything set/outputted as part of the main command

type ArtifactType

type ArtifactType string
const (
	FileArtifactType   ArtifactType = "file"
	DotEnvArtifactType ArtifactType = "dotenv"
	// RuntimeEnvArtifactType captures any exported/set variables inside a task execution
	// Stores them in task output which can later be used inside a pipeline
	// [Experimental]
	RuntimeEnvArtifactType ArtifactType = "env"
)

type RequiredInput added in v0.6.0

type RequiredInput struct {
	// Vars is a list of required variables by the task
	// It is case sensitive
	// It checks both the default vars, supplied vars, and Environment variables
	Vars []string `yaml:"vars,omitempty" json:"vars,omitempty"`
	// Env will identify any missing environment variables
	// It checks complete env vars - merged from global > context > pipeline > task
	Env []string `yaml:"env,omitempty" json:"env,omitempty"`
	// Args checks any args supplied after `--`
	Args []string `yaml:"args,omitempty" json:"args,omitempty"`
}

func (*RequiredInput) Check added in v0.6.0

func (ri *RequiredInput) Check(env *variables.Variables, vars *variables.Variables) error

CheckRequired ensures all required environment are specified/present and not empty

This is a runtime checkinput

func (*RequiredInput) HasRequired added in v0.6.0

func (ri *RequiredInput) HasRequired() bool

type Task

type Task struct {
	Commands     []string // Commands to run
	Context      string
	Env          *variables.Variables
	EnvFile      *utils.Envfile
	Variables    *variables.Variables
	Variations   []map[string]string
	Dir          string
	Timeout      *time.Duration
	AllowFailure bool
	After        []string
	Before       []string
	Interactive  bool
	// ResetContext is useful if multiple variations are running in the same task
	ResetContext bool
	Condition    string
	Artifacts    *Artifact

	Name        string
	Description string
	Required    *RequiredInput

	Generator  map[string]any
	SourceFile string
	// contains filtered or unexported fields
}

Task is a structure that describes task, its commands, environment, working directory etc. After task completes it provides task's execution status, exit code, stdout and stderr

func FromCommands

func FromCommands(name string, commands ...string) *Task

FromCommands creates task new Task instance with given commands

func NewTask

func NewTask(name string) *Task

NewTask creates new Task instance

func (*Task) Duration

func (t *Task) Duration() time.Duration

Duration returns task's execution duration

func (*Task) End

func (t *Task) End() time.Time

func (*Task) Error

func (t *Task) Error() error

func (*Task) ErrorMessage

func (t *Task) ErrorMessage() string

ErrorMessage returns message of the error occurred during task execution

func (*Task) Errored

func (t *Task) Errored() bool

func (*Task) ExitCode

func (t *Task) ExitCode() int16

func (*Task) FromTask

func (t *Task) FromTask(task *Task)

func (*Task) GetVariations

func (t *Task) GetVariations() []map[string]string

GetVariations returns array of maps which are task's variations if no variations exist one is returned to create the default job

func (*Task) HandleOutputCapture added in v0.7.0

func (t *Task) HandleOutputCapture(b []byte)

HandleOutputCapture

func (*Task) Output

func (t *Task) Output() string

Output returns task's stdout as a string

This is left as a legacy method for now. will be removed in the stable 2.x versions

func (*Task) OutputCaptured added in v0.7.0

func (t *Task) OutputCaptured() map[string]string

func (*Task) Skipped

func (t *Task) Skipped() bool

func (*Task) Start

func (t *Task) Start() time.Time

func (*Task) WithEnd

func (t *Task) WithEnd(end time.Time) *Task

func (*Task) WithEnv

func (t *Task) WithEnv(key, value string) *Task

WithEnv sets environment variable

func (*Task) WithError

func (t *Task) WithError(val error) *Task

errored bool

func (*Task) WithExitCode

func (t *Task) WithExitCode(val int16) *Task

exitCode int16

func (*Task) WithSkipped

func (t *Task) WithSkipped(val bool) *Task

func (*Task) WithStart

func (t *Task) WithStart(start time.Time) *Task

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL