pipeline

package module
v0.19.1 Latest Latest
Warning

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

Go to latest
Published: Nov 25, 2026 License: MIT Imports: 17 Imported by: 9 modules, 10 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

README

go-pipeline

Build status Go Reference

go-pipeline is a Go library used for building and modifying Buildkite pipelines in golang. It's used internally by the Buildkite Agent to inspect and sign pipelines prior to uploading them, but is also useful for building tools that generate pipelines.

Installation

To install, run

go get -u github.com/buildkite/go-pipeline

This will add go-pipeline to your go.mod file, and make it available for use in your project.

Usage

Loading a pipeline from yaml
const aPipeline = `
env:
  MOUNTAIN: cotopaxi
  COUNTRY: ecuador

steps:
  - command: echo "hello world"
  - wait
  - command: echo "goodbye world"
`

p, err := pipeline.Parse(strings.NewReader(aPipeline))
if err != nil {
  panic(err)
}

pretty.Println(p)
// &pipeline.Pipeline{
//   Env: &ordered.Map[string,string]{
//     items: {
//       {Key:"MOUNTAIN", Value:"cotopaxi", deleted:false},
//       {Key:"COUNTRY", Value:"ecuador", deleted:false},
//     },
//     index: {"MOUNTAIN":0, "COUNTRY":1},
//   },
//   Steps: {
//     &pipeline.CommandStep{
//       Command:         "echo \"hello world\"",
//       Env:             {},
//       RemainingFields: {},
//     },
//     &pipeline.WaitStep{
//       Scalar:  "wait",
//       Contents: {},
//     },
//     &pipeline.CommandStep{
//       Command:         "echo \"goodbye world\"",
//       Env:             {},
//       RemainingFields: {},
//     },
//   },
//   RemainingFields: {},
// }
Marshalling to YAML or JSON
aPipeline := `...`
p, err := pipeline.Parse(strings.NewReader(aPipeline))
if err != nil {
  // ...
}

//... modify the pipeline

// Marshal to YAML
b, err := yaml.Marshal(p)
if err != nil {
  // ...
}

// Marshal to JSON
b, err := json.Marshal(p)
if err != nil {
  // ...
}

Caveats

The pipeline object model (Pipeline, Steps, Plugin, etc) have these caveats:

  • It is incomplete: there may be fields accepted by the API that are not listed. Do not treat Pipeline, CommandStep, etc, as comprehensive reference guides for how to write a pipeline.
  • It normalises: unmarshaling accepts a variety of step forms, but marshaling back out produces more normalised output. An unmarshal/marshal round-trip may produce different output.
  • It is non-canonical: using the object model does not guarantee that a pipeline will be accepted by the pipeline upload API.

Notably, most of the structs defined by this module only contain the elements of a pipeline (and steps) necessary for the agent to understand, and are (at the time of writing) not comprehensive. Where relevant - that is, where there are more fields that are not included in the struct - the RemainingFields field is used to capture the remaining fields as a map[string]any. This allows pipelines to be loaded and modified without losing information, even if the pipeline contains fields that are not yet understood by the agent.

For example, the command step:

command: echo "hello world"
env:
  FOO: bar
  BAZ: qux
artifact_paths:
  - "logs/**/*"
  - "coverage/**/*"
parallelism: 5

would be represented in go as:

&pipeline.CommandStep{
  Command: `echo "hello world"`,
  Env: ordered.MapFromItems(
    ordered.TupleSS("FOO", "bar"),
    ordered.TupleSS("BAZ", "qux"),
  ),
  ArtifactPaths: []string{"logs/**/*", "coverage/**/*"},
  RemainingFields: map[string]any{
    "parallelism": 5,
  },
}

This go struct would be marshaled back out to YAML equivalent to the original input.

Checkout

The checkout block configures git checkout behavior for a pipeline or a command step. It supports skip, submodules, depth, lfs, ssh_secret, commit_verification, and a nested flags mapping. skip, lfs and submodules are *bool, so the model preserves the difference between true, false, and an absent value; depth (*int) and ssh_secret (*string) keep the same distinction between an explicit value and an absent one; flags carries per-phase git overrides. commit_verification is a string and supports warn or strict values.

The simplest case opts a step out of checkout entirely:

steps:
  - command: echo "no git checkout for me"
    checkout:
      skip: true

skip: false at the step level explicitly overrides any pipeline-level or agent-level default that would otherwise skip checkout; an absent skip inherits whatever default applies. Round-trips preserve the distinction, so skip: false does not collapse to an empty mapping.

skip maps to BUILDKITE_SKIP_CHECKOUT on the agent: true skips the checkout phase, absent leaves it to the agent default. submodules follows the same tristate pattern and maps to BUILDKITE_GIT_SUBMODULES: true and false set the env var explicitly, absent leaves it to the agent default.

ssh_secret holds the name or ID of a Buildkite Secret containing an SSH private key the agent uses for git checkout. The agent owns retrieval and validation; go-pipeline only parses and round-trips the value.

steps:
  - command: make test
    checkout:
      ssh_secret: deploy-key

commit_verification enables a verification step which ensures that the specified commit SHA genuinely exists on the specified branch. Allowed values are warn or strict. warn logs a warning but allows the checkout to proceed; strict will fail the checkout with an error if it determines that the SHA doesn't exist on the branch.

steps:
  - command: build.sh
    checkout:
      commit_verification: strict

flags carries per-phase git invocation overrides for clone, fetch, checkout, and clean:

steps:
  - command: build.sh
    checkout:
      flags:
        clone: "--depth 1"
        fetch: "--prune"
        checkout: "--force"
        clean: "-fdx"

Each leaf is *string. Omitting a flag leaves whatever default the consumer applies; an explicit empty string (clone: "") is preserved through round-trips and signals "no flags for this phase". Non-string scalars (clone: 42, clone: true) are rejected at parse time, since the value passes through to git as flag text and coercion would silently produce broken invocations. Unknown keys under flags: land in RemainingFields, so a pipeline using a flag name this library doesn't yet recognize still parses and round-trips cleanly.

A pipeline-level checkout provides defaults for command steps. Inheritance is opt-in: the consumer merges pipeline values into each step. After merging the step value wins per leaf, with anything the step didn't set inherited from the pipeline, at both the top level and inside flags:

checkout:
  skip: true

steps:
  - command: echo "inherits skip: true from the pipeline"

  - command: echo "explicit override - checkout runs"
    checkout:
      skip: false

After merging, the second step has skip: false (step wins) and the first step has skip: true (inherited).

The conventional ordering is Pipeline.Interpolate first, then merge per step before dispatching to the agent.

Both checkout: and flags: must be mappings. Non-mapping shapes (scalars, including the checkout: true / checkout: false shorthand, and sequences) are rejected at parse time. Opt-out is spelled checkout: { skip: true }.

Pipelines signed before checkout was a signed field will fail to verify if the step now carries any non-empty Checkout data (for example a step that sets only submodules). Re-sign such pipelines when rolling forward to a verifier that includes checkout.

Checkout.Depth is a *int for the same reason as Skip, this is distinguishable from any explicit value, so an inherited pipeline level depth can be cleanly overridden at the step level. The backend validates depth >= 1, this library does not.

checkout:
  depth: 10

steps:
  - command: echo "Shallow depth defaulting to 10 from build level checkout"

  - command: echo "Deeper shallow at the step level"
    checkout:
      depth: 50

lfs is a *bool following the same tristate pattern as skip and submodules: true and false set the behaviour explicitly, an absent value leaves it to the agent default. A step inherits the pipeline-level lfs unless it sets its own.

checkout:
  lfs: true

steps:
  - command: echo "inherits lfs: true from the pipeline"

  - command: echo "explicit override - no LFS for this step"
    checkout:
      lfs: false

What's up with the ordered module?

While implementing the pipeline module, we ran into a problem: in some cases, in the buildkite pipeline.yaml, the order of map fields is significant. Because of this, whenever the pipeline gets unmarshaled from YAML or JSON, it needs to be stored in a way that preserves the order of the fields. The ordered module is a simple implementation of an ordered map. In most cases, when the pipeline is dealing with user-input maps, it will store them internally as ordered.Maps. When the pipeline is marshaled back out to YAML or JSON, the ordered.Maps will be marshaled in the correct order.

Contributing

Contributions, bugfixes, issues and PRs are always welcome! Please see CONTRIBUTING.md for more details.

Documentation

Overview

Package pipeline implements the pieces necessary for the agent to work with pipelines (typically in YAML or JSON form).

The pipeline object model (Pipeline, Steps, Plugin, etc) have these caveats:

  • It is incomplete: there may be fields accepted by the API that are not listed. Do not treat Pipeline, CommandStep, etc, as comprehensive reference guides for how to write a pipeline.
  • It normalises: unmarshaling accepts a variety of step forms, but marshaling back out produces more normalised output. An unmarshal/marshal round-trip may produce different output.
  • It is non-canonical: using the object model does not guarantee that a pipeline will be accepted by the pipeline upload API.

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrStepTypeInference = errors.New("cannot infer step type")
	ErrUnknownStepType   = errors.New("unknown step type")
)

Sentinel errors that can appear when falling back to UnknownStep.

Functions

func ParseAll added in v0.14.0

func ParseAll(src io.Reader) iter.Seq2[*Pipeline, error]

ParseAll parses all YAML documents in the input stream as pipelines. It does not stop yielding on decoding or unmarshaling errors. It does not apply interpolation.

Warnings are passed through the err return:

for p, err := range ParseAll(src) {
	if w := warning.As(err); w != nil {
		// Here are some warnings that should be shown
		log.Printf("*Warning* - pipeline is not fully parsed:\n%v", w)
	} else if err != nil {
		// Parse could not understand src at all
		return err
	}
	// Use p
}

Types

type Cache added in v0.6.0

type Cache struct {
	Disabled bool     `yaml:",omitempty"`
	Name     string   `yaml:"name,omitempty"`
	Paths    []string `yaml:"paths,omitempty"`
	Size     string   `yaml:"size,omitempty"`

	RemainingFields map[string]any `yaml:",inline"`
}

Cache models the cache settings for a given step

func (*Cache) MarshalJSON added in v0.7.0

func (c *Cache) MarshalJSON() ([]byte, error)

MarshalJSON marshals the step to JSON. Special handling is needed because yaml.v3 has "inline" but encoding/json has no concept of it.

func (*Cache) UnmarshalOrdered added in v0.6.0

func (c *Cache) UnmarshalOrdered(o any) error

UnmarshalOrdered unmarshals from the following types: - string: a single path - []string: multiple paths - ordered.Map: a map containing paths, among potentially other things

type Checkout added in v0.18.0

type Checkout struct {
	// Skip maps to BUILDKITE_SKIP_CHECKOUT on the agent.
	Skip *bool `yaml:"skip,omitempty"`
	// Submodules maps to BUILDKITE_GIT_SUBMODULES on the agent.
	Submodules *bool `yaml:"submodules,omitempty"`
	// SSHSecret names a Buildkite Secret holding an SSH private key the agent
	// uses for git checkout; *string preserves the set/empty/absent tristate.
	// The explicit json tag is required because the snake_case key does not
	// case-insensitively match the field name (unlike skip/submodules), so
	// json.Unmarshal would otherwise drop it. Marshal output is unaffected:
	// inlineFriendlyMarshalJSON derives JSON keys from the yaml tag.
	SSHSecret *string `json:"ssh_secret,omitempty" yaml:"ssh_secret,omitempty"`
	// CommitVerification controls whether the agent verifies the commit
	// exists on the expected branch. "strict" fails on definitive mismatch;
	// "warn" only logs. Empty disables verification.
	CommitVerification string `json:"commit_verification,omitempty" yaml:"commit_verification,omitempty"`
	// Depth performs a shallow clone of the given depth. nil leaves the
	// agent default (full clone).
	Depth *int `yaml:"depth,omitempty"`
	// LFS enables Git LFS when checking out. nil leaves the agent default.
	LFS *bool `yaml:"lfs,omitempty"`
	// Sparse configures sparse checkout. nil = unset (full checkout).
	Sparse *Sparse        `yaml:"sparse,omitempty"`
	Flags  *CheckoutFlags `yaml:"flags,omitempty"`

	RemainingFields map[string]any `yaml:",inline"`
}

Checkout models the checkout settings block on a command step or pipeline. Skip, Submodules, SSHSecret, and Depth sit at the top level; per-flag overrides live under the nested flags: key. Any other keys directly under checkout: land in RemainingFields and survive a round-trip but are not interpreted.

Direct json.Unmarshal into a Checkout drops inline RemainingFields; route through CommandStep or Pipeline to preserve them.

func (*Checkout) IsEmpty added in v0.18.0

func (c *Checkout) IsEmpty() bool

IsEmpty reports whether the checkout is nil or has no fields set. Used by signing and merging to canonicalise empty/nil values.

func (*Checkout) MarshalJSON added in v0.18.0

func (c *Checkout) MarshalJSON() ([]byte, error)

MarshalJSON marshals to JSON. Special handling is needed because yaml.v3 has "inline" but encoding/json has no concept of it.

func (*Checkout) UnmarshalOrdered added in v0.18.0

func (c *Checkout) UnmarshalOrdered(o any) error

UnmarshalOrdered unmarshals a Checkout from an ordered map. Bool inputs are rejected; see the error message for the supported form. Scalar and list shapes are also rejected so misconfigurations fail loudly. Null is handled before this method is called and leaves Checkout nil.

type CheckoutFlags added in v0.18.0

type CheckoutFlags struct {
	Clone    *string `yaml:"clone,omitempty"`
	Fetch    *string `yaml:"fetch,omitempty"`
	Checkout *string `yaml:"checkout,omitempty"`
	Clean    *string `yaml:"clean,omitempty"`

	RemainingFields map[string]any `yaml:",inline"`
}

CheckoutFlags models the per-step git flag overrides under checkout.flags. Pointer fields distinguish unset (nil, omitted) from explicit empty ("", preserved as flag removal).

func (*CheckoutFlags) MarshalJSON added in v0.18.0

func (f *CheckoutFlags) MarshalJSON() ([]byte, error)

MarshalJSON is needed to use inlineFriendlyMarshalJSON.

func (*CheckoutFlags) UnmarshalOrdered added in v0.18.0

func (f *CheckoutFlags) UnmarshalOrdered(o any) error

UnmarshalOrdered unmarshals a CheckoutFlags from an ordered map and rejects non-string scalar values under any typed leaf (clone, fetch, checkout, clean). The default for *string targets in ordered.Unmarshal is fmt.Sprint coercion, which would silently turn 'clone: true' into Clone = ptr("true") and produce a broken git invocation downstream. Strict typing fails loudly instead. Unknown keys still land in RemainingFields with any type.

type CommandStep

type CommandStep struct {
	// Fields common to various step types
	Key   string `yaml:"key,omitempty" aliases:"id,identifier"`
	Label string `yaml:"label,omitempty" aliases:"name"`

	// Fields that are meaningful specifically for command steps
	Command       string            `yaml:"command"`
	Plugins       Plugins           `yaml:"plugins,omitempty"`
	Secrets       Secrets           `yaml:"secrets,omitempty"`
	Env           map[string]string `yaml:"env,omitempty"`
	Signature     *Signature        `yaml:"signature,omitempty"`
	Matrix        *Matrix           `yaml:"matrix,omitempty"`
	Cache         *Cache            `yaml:"cache,omitempty"`
	Checkout      *Checkout         `yaml:"checkout,omitempty"`
	ArtifactPaths []string          `yaml:"artifact_paths,omitempty" aliases:"artifacts"`

	// RemainingFields stores any other top-level mapping items so they at least
	// survive an unmarshal-marshal round-trip.
	RemainingFields map[string]any `yaml:",inline"`
	// contains filtered or unexported fields
}

CommandStep models a command step.

Standard caveats apply - see the package comment.

func (*CommandStep) InterpolateMatrixPermutation

func (c *CommandStep) InterpolateMatrixPermutation(mp MatrixPermutation) error

InterpolateMatrixPermutation validates and then interpolates the choice of matrix values into the step. This should only be used in order to validate a job that's about to be run, and not used before pipeline upload.

func (*CommandStep) MarshalJSON

func (c *CommandStep) MarshalJSON() ([]byte, error)

MarshalJSON marshals the step to JSON. Special handling is needed because yaml.v3 has "inline" but encoding/json has no concept of it.

func (*CommandStep) MergeCheckoutFromPipeline added in v0.18.0

func (c *CommandStep) MergeCheckoutFromPipeline(pipelineCheckout *Checkout)

MergeCheckoutFromPipeline merges pipeline-level checkout config into this step's checkout. Step-level values take precedence per leaf; an empty parent is a no-op.

The receiver's Checkout is mutated in place, so callers that share a *Checkout across steps (e.g. via programmatic construction) must copy first. The parse path materialises an independent Checkout per step.

func (*CommandStep) MergeSecretsFromPipeline added in v0.16.0

func (c *CommandStep) MergeSecretsFromPipeline(pipelineSecrets Secrets)

MergeSecretsFromPipeline merges pipeline-level secrets with this step's secrets. Step-level secrets take precedence over pipeline-level secrets for deduplication.

func (*CommandStep) UnmarshalJSON

func (c *CommandStep) UnmarshalJSON(b []byte) error

UnmarshalJSON is used when unmarshalling an individual step directly, e.g. from the Agent API Accept Job.

func (*CommandStep) UnmarshalOrdered

func (c *CommandStep) UnmarshalOrdered(src any) error

UnmarshalOrdered unmarshals a command step from an ordered map.

type GroupStep

type GroupStep struct {
	// Fields common to various step types
	Key string `yaml:"key,omitempty" aliases:"id,identifier"`

	// Group must always exist in a group step (so that we know it is a group).
	// If it has a value, it is treated as equivalent to the label or name.
	Group *string `yaml:"group" aliases:"label,name"`

	Steps Steps `yaml:"steps"`

	// RemainingFields stores any other top-level mapping items so they at least
	// survive an unmarshal-marshal round-trip.
	RemainingFields map[string]any `yaml:",inline"`
}

GroupStep models a group step.

Standard caveats apply - see the package comment.

func (*GroupStep) MarshalJSON

func (g *GroupStep) MarshalJSON() ([]byte, error)

MarshalJSON marshals the step to JSON. Special handling is needed because yaml.v3 has "inline" but encoding/json has no concept of it.

func (*GroupStep) UnmarshalOrdered

func (g *GroupStep) UnmarshalOrdered(src any) error

UnmarshalOrdered unmarshals a group step from an ordered map.

type InputStep

type InputStep struct {
	Scalar   string         `yaml:"-"`
	Contents map[string]any `yaml:",inline"`
}

InputStep models a block or input step.

Standard caveats apply - see the package comment.

func (*InputStep) MarshalJSON

func (s *InputStep) MarshalJSON() ([]byte, error)

MarshalJSON marshals s.Scalar if it's not empty, otherwise s.Contents if that is not empty. If both s.Scalar and s.Contents are empty, it reports an error.

func (*InputStep) MarshalYAML added in v0.4.1

func (s *InputStep) MarshalYAML() (any, error)

MarshalYAML returns s.Scalar if it's not empty, otherwise s.Contents if that is not empty. If both s.Scalar and s.Contents are empty, it reports an error.

type InterpolationEnv added in v0.4.0

type InterpolationEnv interface {
	Get(name string) (string, bool)
	Set(name string, value string)
}

InterpolationEnv contains environment variables that may be interpolated into a pipeline. Users may define an equivalence between environment variable name, for example the environment variable names may case-insensitive.

type Matrix

type Matrix struct {
	Setup       MatrixSetup       `yaml:"setup"`
	Adjustments MatrixAdjustments `yaml:"adjustments,omitempty"`

	RemainingFields map[string]any `yaml:",inline"`
}

Matrix models the matrix specification for command steps.

func (*Matrix) IsEmpty added in v0.11.0

func (m *Matrix) IsEmpty() bool

IsEmpty reports whether the matrix is empty (is nil, or has no setup, no adjustments, and no other data within it).

func (*Matrix) MarshalJSON

func (m *Matrix) MarshalJSON() ([]byte, error)

MarshalJSON is needed to use inlineFriendlyMarshalJSON, and reduces the representation to a single list if the matrix is simple.

func (*Matrix) MarshalYAML

func (m *Matrix) MarshalYAML() (any, error)

MarshalYAML is needed to reduce the representation to a single slice if the matrix is simple.

func (*Matrix) UnmarshalOrdered

func (m *Matrix) UnmarshalOrdered(o any) error

UnmarshalOrdererd unmarshals from either []any or *ordered.MapSA.

type MatrixAdjustment

type MatrixAdjustment struct {
	With MatrixAdjustmentWith `yaml:"with"`
	Skip any                  `yaml:"skip,omitempty"`

	RemainingFields map[string]any `yaml:",inline"` // NB: soft_fail is in the remaining fields
}

MatrixAdjustment models an adjustment - a combination of (possibly new) matrix values, and skip/soft fail configuration.

func (*MatrixAdjustment) MarshalJSON

func (ma *MatrixAdjustment) MarshalJSON() ([]byte, error)

MarshalJSON is needed to use inlineFriendlyMarshalJSON.

func (*MatrixAdjustment) ShouldSkip

func (ma *MatrixAdjustment) ShouldSkip() bool

type MatrixAdjustmentWith

type MatrixAdjustmentWith map[string]string

MatrixAdjustmentWith is either a map of dimension key -> dimension value, or a single value (for single anonymous dimension matrices).

func (MatrixAdjustmentWith) MarshalJSON

func (maw MatrixAdjustmentWith) MarshalJSON() ([]byte, error)

MarshalJSON returns either a single scalar or an object.

func (MatrixAdjustmentWith) MarshalYAML

func (maw MatrixAdjustmentWith) MarshalYAML() (any, error)

MarshalYAML returns either a single scalar or a map.

func (*MatrixAdjustmentWith) UnmarshalOrdered

func (maw *MatrixAdjustmentWith) UnmarshalOrdered(o any) error

UnmarshalOrdered unmarshals from either a scalar value (string, bool, or int) or *ordered.MapSA.

type MatrixAdjustments

type MatrixAdjustments []*MatrixAdjustment

MatrixAdjustments is a set of adjustments.

type MatrixPermutation

type MatrixPermutation map[string]string

MatrixPermutation represents a possible permutation of a matrix.

type MatrixSetup

type MatrixSetup map[string][]string

MatrixSetup is the main setup of a matrix - one or more dimensions. The cross product of the dimensions in the setup produces the base combinations of matrix values.

func (MatrixSetup) MarshalJSON

func (ms MatrixSetup) MarshalJSON() ([]byte, error)

MarshalJSON returns either a list (if the setup is a single anonymous dimension) or an object (if it contains one or more (named) dimensions).

func (MatrixSetup) MarshalYAML

func (ms MatrixSetup) MarshalYAML() (any, error)

MarshalYAML returns either a Scalars (if the setup is a single anonymous dimension) or a map (if it contains one or more (named) dimensions).

func (*MatrixSetup) UnmarshalOrdered

func (ms *MatrixSetup) UnmarshalOrdered(o any) error

UnmarshalOrdered unmarshals from either []any or *ordered.MapSA.

type Options added in v0.9.0

type Options func(*Pipeline)

Options are functional options for creating a new Env.

type Pipeline

type Pipeline struct {
	Steps    Steps          `yaml:"steps"`
	Env      *ordered.MapSS `yaml:"env,omitempty"`
	Secrets  Secrets        `yaml:"secrets,omitempty"`
	Checkout *Checkout      `yaml:"checkout,omitempty"`

	// RemainingFields stores any other top-level mapping items so they at least
	// survive an unmarshal-marshal round-trip.
	RemainingFields map[string]any `yaml:",inline"`
}

Pipeline models a pipeline.

Standard caveats apply - see the package comment.

func Parse

func Parse(src io.Reader) (*Pipeline, error)

Parse parses a pipeline. It does not apply interpolation. Note that it only parses the first YAML document in the input. To parse all YAML documents in the input reader as pipelines, use ParseAll.

Warnings are passed through the err return:

p, err := Parse(src)
if w := warning.As(err); w != nil {
	// Here are some warnings that should be shown
	log.Printf("*Warning* - pipeline is not fully parsed:\n%v", w)
} else if err != nil {
    // Parse could not understand src at all
    return err
}
// Use p

func (*Pipeline) Interpolate

func (p *Pipeline) Interpolate(interpolationEnv InterpolationEnv, preferRuntimeEnv bool) error

Interpolate interpolates variables defined in both interpolationEnv and p.Env into the pipeline. More specifically, it does these things:

  • Interpolate pipeline.Env and copy the results into interpolationEnv, provided they don't conflict, to apply later.
  • Interpolate any string value in the rest of the pipeline.

By default if an environment variable exists in both the runtime and pipeline env we will substitute with the pipeline env IF the pipeline env is defined first. Setting the preferRuntimeEnv option to true instead prefers the runtime environment to pipeline environment variables when both are defined.

func (*Pipeline) MarshalJSON

func (p *Pipeline) MarshalJSON() ([]byte, error)

MarshalJSON marshals a pipeline to JSON. Special handling is needed because yaml.v3 has "inline" but encoding/json has no concept of it.

func (*Pipeline) UnmarshalOrdered

func (p *Pipeline) UnmarshalOrdered(o any) error

UnmarshalOrdered unmarshals the pipeline from either []any (a legacy sequence of steps) or *ordered.MapSA (a modern pipeline configuration).

type Plugin

type Plugin struct {
	Source string
	Config any
}

Plugin models plugin configuration.

Standard caveats apply - see the package comment.

func (*Plugin) FullSource

func (p *Plugin) FullSource() string

FullSource attempts to canonicalise Source. If it fails, it returns Source unaltered. Otherwise, it resolves sources in a manner described at https://buildkite.com/docs/plugins/using#plugin-sources.

func (*Plugin) MarshalJSON

func (p *Plugin) MarshalJSON() ([]byte, error)

MarshalJSON returns the plugin in "one-key object" form. Plugin sources are marshalled into "full" form. Plugins originally specified as a single string (no config, only source) are canonicalised into "one-key object" with config null.

func (*Plugin) MarshalYAML

func (p *Plugin) MarshalYAML() (any, error)

MarshalYAML returns the plugin in "one-item map" form. Plugin sources are marshalled into "full" form. Plugins originally specified as a single string (no config, only source) are canonicalised into "one-item map" with config nil. Configs that are zero-length maps are canonicalised to nil.

type Plugins

type Plugins []*Plugin

Plugins is a sequence of plugins. It is useful for unmarshaling.

func (*Plugins) UnmarshalJSON

func (p *Plugins) UnmarshalJSON(b []byte) error

UnmarshalJSON is used mainly to normalise the BUILDKITE_PLUGINS env var.

func (*Plugins) UnmarshalOrdered

func (p *Plugins) UnmarshalOrdered(o any) error

UnmarshalOrdered unmarshals Plugins from either

  • []any - originally a sequence of "one-item mappings" (normal form), or
  • *ordered.MapSA - a mapping (where order is important...non-normal form).

"plugins" is supposed to be a sequence of one-item maps, since order matters. But some people (even us) write plugins into one big mapping and rely on order preservation.

type Secret added in v0.16.0

type Secret struct {
	Key                 string         `json:"key" yaml:"key"`
	EnvironmentVariable string         `json:"environment_variable,omitempty" yaml:"environment_variable,omitempty"`
	RemainingFields     map[string]any `yaml:",inline"`
}

Secret represents a pipeline secret configuration.

func (Secret) MarshalJSON added in v0.16.0

func (s Secret) MarshalJSON() ([]byte, error)

MarshalJSON marshals the secret to JSON.

type Secrets added in v0.16.0

type Secrets []Secret

Secrets is a sequence of secrets. It is useful for unmarshaling.

func (Secrets) MarshalYAML added in v0.16.0

func (s Secrets) MarshalYAML() (any, error)

func (Secrets) MergeWith added in v0.16.0

func (s Secrets) MergeWith(other Secrets) Secrets

MergeWith merges these secrets with another set of secrets, with the other secrets taking precedence. Deduplication is performed based on the EnvironmentVariable field.

func (*Secrets) UnmarshalJSON added in v0.16.0

func (s *Secrets) UnmarshalJSON(b []byte) error

UnmarshalJSON is used for JSON unmarshaling.

func (*Secrets) UnmarshalOrdered added in v0.16.0

func (s *Secrets) UnmarshalOrdered(o any) error

UnmarshalOrdered unmarshals Secrets from []any (sequence of secret names).

type Signature

type Signature struct {
	Algorithm    string   `json:"algorithm" yaml:"algorithm"`
	SignedFields []string `json:"signed_fields" yaml:"signed_fields"`
	Value        string   `json:"value" yaml:"value"`
}

Signature models a signature (on a step, etc).

type Sparse added in v0.18.0

type Sparse struct {
	// Paths is the list of paths to include in the sparse checkout.
	Paths []string `json:"paths,omitempty" yaml:"paths,omitempty"`
	// RemainingFields stores any other mapping items so they at least
	// survive an unmarshal-marshal round-trip.
	RemainingFields map[string]any `yaml:",inline"`
}

Sparse models sparse checkout configuration.

func (*Sparse) MarshalJSON added in v0.18.0

func (s *Sparse) MarshalJSON() ([]byte, error)

MarshalJSON marshals Sparse to JSON. Special handling is needed because yaml.v3 has "inline" but encoding/json has no concept of it.

func (*Sparse) UnmarshalOrdered added in v0.18.0

func (s *Sparse) UnmarshalOrdered(o any) error

UnmarshalOrdered unmarshals a Sparse from an ordered map.

type Step

type Step interface {
	// contains filtered or unexported methods
}

Step models a step in the pipeline. It will be a pointer to one of: - CommandStep - WaitStep - InputStep - TriggerStep - GroupStep

func NewScalarStep

func NewScalarStep(s string) (Step, error)

NewScalarStep returns a Step that can be represented as a single string. Currently these are "wait", "block", "input", and some deprecated variations ("waiter", "manual"). If it is any other string, NewScalarStep returns an UnknownStep containing an error wrapping ErrUnknownStepType.

type Steps

type Steps []Step

Steps contains multiple steps. It is useful for unmarshaling step sequences, since it has custom logic for determining the correct step type.

func (*Steps) UnmarshalOrdered

func (s *Steps) UnmarshalOrdered(o any) error

UnmarshalOrdered unmarshals a slice ([]any) into a slice of steps.

type TriggerStep

type TriggerStep struct {
	Contents map[string]any `yaml:",inline"`
}

TriggerStep models a trigger step.

Standard caveats apply - see the package comment.

func (TriggerStep) MarshalJSON

func (t TriggerStep) MarshalJSON() ([]byte, error)

MarshalJSON marshals the contents of the step.

type UnknownStep

type UnknownStep struct {
	Contents any
}

UnknownStep models any step we don't know how to represent in this version. When future step types are added, they should be parsed with more specific types. UnknownStep is present to allow older parsers to preserve newer pipelines.

func (*UnknownStep) MarshalJSON

func (u *UnknownStep) MarshalJSON() ([]byte, error)

MarshalJSON marshals the contents of the step.

func (*UnknownStep) MarshalYAML

func (u *UnknownStep) MarshalYAML() (any, error)

MarshalYAML returns the contents of the step.

func (*UnknownStep) UnmarshalOrdered

func (u *UnknownStep) UnmarshalOrdered(src any) error

UnmarshalOrdered unmarshals an unknown step.

type WaitStep

type WaitStep struct {
	Scalar   string         `yaml:"-"`
	Contents map[string]any `yaml:",inline"`
}

WaitStep models a wait step.

Standard caveats apply - see the package comment.

func (*WaitStep) MarshalJSON

func (s *WaitStep) MarshalJSON() ([]byte, error)

MarshalJSON marshals a wait step as "wait" if the step is empty, or as the s.Scalar if it is not empty, or as s.Contents.

func (*WaitStep) MarshalYAML added in v0.4.1

func (s *WaitStep) MarshalYAML() (any, error)

MarshalYAML returns a wait step as "wait" if the step is empty, or as the s.Scalar if it is not empty, or as s.Contents.

Directories

Path Synopsis
internal
env
Package env contains data structures and methods to assist with managing environment variables.
Package env contains data structures and methods to assist with managing environment variables.
Package jwkutil provides utilities for working with JSON Web Keys and JSON Web Key Sets as defined in [RFC 7517].
Package jwkutil provides utilities for working with JSON Web Keys and JSON Web Key Sets as defined in [RFC 7517].
Package ordered implements an ordered map type, suitable for use when decoding yaml documents where mappings must be preserved, such as in certain parts of the buildkite pipeline yaml.
Package ordered implements an ordered map type, suitable for use when decoding yaml documents where mappings must be preserved, such as in certain parts of the buildkite pipeline yaml.
Package signature implements signing and verification of pipeline steps.
Package signature implements signing and verification of pipeline steps.
Package warning provides a warning error type (a "soft" multi-error).
Package warning provides a warning error type (a "soft" multi-error).

Jump to

Keyboard shortcuts

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