jx: github.com/jenkins-x/jx/pkg/tekton/syntax Index | Files | Directories

package syntax

import "github.com/jenkins-x/jx/pkg/tekton/syntax"

+k8s:deepcopy-gen=package +k8s:openapi-gen=true Package v1 is the v1 version of the API. +groupName=config.jenkins.io +apiVersion=v1

Index

Package Files

constants.go doc.go pipeline.go zz_generated.deepcopy.go

Constants

const (
    // TektonAPIVersion the APIVersion for using Tekton
    TektonAPIVersion = "tekton.dev/v1alpha1"

    // LabelStageName - the name for the label that will have the stage name on the Task.
    LabelStageName = "jenkins.io/task-stage-name"

    // DefaultStageNameForBuildPack - the name we use for the single stage created from build packs currently.
    DefaultStageNameForBuildPack = "from-build-pack"

    // KanikoDockerImage - the default image used for Kaniko builds
    KanikoDockerImage = "gcr.io/kaniko-project/executor:9912ccbf8d22bbafbf971124600fbb0b13b9cbd6"

    // DefaultContainerImage - the default image used for pipelines if none is specified.
    DefaultContainerImage = "gcr.io/jenkinsxio/builder-maven"
)
const (
    // GitMergeImage is the default image name that is used in the git merge step of a pipeline
    GitMergeImage = "gcr.io/jenkinsxio/builder-jx"

    // WorkingDirRoot is the root directory for working directories.
    WorkingDirRoot = "/workspace"
)

func EnvMapToSlice Uses

func EnvMapToSlice(envMap map[string]corev1.EnvVar) []corev1.EnvVar

EnvMapToSlice transforms a map of environment variables into a slice that can be used in container configuration

func MangleToRfc1035Label Uses

func MangleToRfc1035Label(body string, suffix string) string

MangleToRfc1035Label - Task/Step names need to be RFC 1035/1123 compliant DNS labels, so we mangle them to make them compliant. Results should match the following regex and be no more than 63 characters long:

[a-z]([-a-z0-9]*[a-z0-9])?

cf. https://kubernetes.io/docs/concepts/overview/working-with-objects/names/#names body is assumed to have at least one ASCII letter. suffix is assumed to be alphanumeric and non-empty. TODO: Combine with kube.ToValidName (that function needs to handle lengths)

func MergeContainers Uses

func MergeContainers(parentContainer, childContainer *corev1.Container) (*corev1.Container, error)

MergeContainers combines parent and child container structs, with the child overriding the parent.

func PipelineRunName Uses

func PipelineRunName(pipelineIdentifier string, buildIdentifier string) string

PipelineRunName returns the pipeline name given the pipeline and build identifier

type Agent Uses

type Agent struct {
    // One of label or image is required.
    Label string `json:"label,omitempty"`
    Image string `json:"image,omitempty"`

    // Legacy fields from jenkinsfile.PipelineAgent
    Container string `json:"container,omitempty"`
    Dir       string `json:"dir,omitempty"`
}

Agent defines where the pipeline, stage, or step should run.

func (*Agent) DeepCopy Uses

func (in *Agent) DeepCopy() *Agent

DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new Agent.

func (*Agent) DeepCopyForParsedPipeline Uses

func (a *Agent) DeepCopyForParsedPipeline() *Agent

DeepCopyForParsedPipeline returns a copy of the Agent with deprecated fields migrated to current ones.

func (*Agent) DeepCopyInto Uses

func (in *Agent) DeepCopyInto(out *Agent)

DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil.

func (*Agent) GetImage Uses

func (a *Agent) GetImage() string

GetImage gets the agent's image to run on, opting for Image if set, then Container.

func (*Agent) Groovy Uses

func (a *Agent) Groovy() string

Groovy returns the agent groovy expression for the agent or `any` if its blank Legacy code for Jenkinsfile generation

type CRDsFromPipelineParams Uses

type CRDsFromPipelineParams struct {
    PipelineIdentifier string
    BuildIdentifier    string
    ResourceIdentifier string
    Namespace          string
    PodTemplates       map[string]*corev1.Pod
    VersionsDir        string
    TaskParams         []tektonv1alpha1.ParamSpec
    SourceDir          string
    Labels             map[string]string
    DefaultImage       string
    InterpretMode      bool
}

CRDsFromPipelineParams is how the parameters to GenerateCRDs are specified

func (*CRDsFromPipelineParams) DeepCopy Uses

func (in *CRDsFromPipelineParams) DeepCopy() *CRDsFromPipelineParams

DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new CRDsFromPipelineParams.

func (*CRDsFromPipelineParams) DeepCopyInto Uses

func (in *CRDsFromPipelineParams) DeepCopyInto(out *CRDsFromPipelineParams)

DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil.

type Loop Uses

type Loop struct {
    // The variable name.
    Variable string `json:"variable"`
    // The list of values to iterate over
    Values []string `json:"values"`
    // The steps to run
    Steps []Step `json:"steps"`
}

Loop is a special step that defines a variable, a list of possible values for that variable, and a set of steps to repeat for each value for the variable, with the variable set with that value in the environment for the execution of those steps.

func (*Loop) DeepCopy Uses

func (in *Loop) DeepCopy() *Loop

DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new Loop.

func (*Loop) DeepCopyInto Uses

func (in *Loop) DeepCopyInto(out *Loop)

DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil.

type ParsedPipeline Uses

type ParsedPipeline struct {
    Agent      *Agent          `json:"agent,omitempty"`
    Env        []corev1.EnvVar `json:"env,omitempty"`
    Options    *RootOptions    `json:"options,omitempty"`
    Stages     []Stage         `json:"stages"`
    Post       []Post          `json:"post,omitempty"`
    WorkingDir *string         `json:"dir,omitempty"`

    // Replaced by Env, retained for backwards compatibility
    Environment []corev1.EnvVar `json:"environment,omitempty"`
}

ParsedPipeline is the internal representation of the Pipeline, used to validate and create CRDs

func ApplyNonStepOverridesToPipeline Uses

func ApplyNonStepOverridesToPipeline(pipeline *ParsedPipeline, override *PipelineOverride) *ParsedPipeline

ApplyNonStepOverridesToPipeline applies the non-step configuration from an individual override to the pipeline.

func ApplyStepOverridesToPipeline Uses

func ApplyStepOverridesToPipeline(pipeline *ParsedPipeline, override *PipelineOverride) *ParsedPipeline

ApplyStepOverridesToPipeline applies an individual override to the pipeline, replacing named steps in specified stages (or all stages if no stage name is specified).

func (*ParsedPipeline) AddContainerEnvVarsToPipeline Uses

func (j *ParsedPipeline) AddContainerEnvVarsToPipeline(origEnv []corev1.EnvVar)

AddContainerEnvVarsToPipeline allows for adding a slice of container environment variables directly to the pipeline, if they're not already defined.

func (*ParsedPipeline) DeepCopy Uses

func (in *ParsedPipeline) DeepCopy() *ParsedPipeline

DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new ParsedPipeline.

func (*ParsedPipeline) DeepCopyInto Uses

func (in *ParsedPipeline) DeepCopyInto(out *ParsedPipeline)

DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil.

func (*ParsedPipeline) GenerateCRDs Uses

func (j *ParsedPipeline) GenerateCRDs(params CRDsFromPipelineParams) (*tektonv1alpha1.Pipeline, []*tektonv1alpha1.Task, *v1.PipelineStructure, error)

GenerateCRDs translates the Pipeline structure into the corresponding Pipeline and Task CRDs

func (*ParsedPipeline) GetEnv Uses

func (j *ParsedPipeline) GetEnv() []corev1.EnvVar

GetEnv gets the environment for the ParsedPipeline, returning Env first and Environment if Env isn't populated.

func (*ParsedPipeline) GetPodLabels Uses

func (j *ParsedPipeline) GetPodLabels() map[string]string

GetPodLabels returns the optional additional labels to apply to all pods for this pipeline. The labels and their values will be converted to RFC1035-compliant strings.

func (*ParsedPipeline) GetPossibleAffinityPolicy Uses

func (j *ParsedPipeline) GetPossibleAffinityPolicy(name string) *corev1.Affinity

GetPossibleAffinityPolicy takes the pipeline name and returns the appropriate affinity policy for pods in this pipeline given its configuration, specifically of options.distributeParallelAcrossNodes.

func (*ParsedPipeline) GetTolerations Uses

func (j *ParsedPipeline) GetTolerations() []corev1.Toleration

GetTolerations returns the tolerations configured in the root options for this pipeline, if any.

func (*ParsedPipeline) Validate Uses

func (j *ParsedPipeline) Validate(context context.Context) *apis.FieldError

Validate checks the parsed ParsedPipeline to find any errors in it. TODO: Improve validation to actually return all the errors via the nested errors? TODO: Add validation for the not-yet-supported-for-CRD-generation sections

type PipelineOverride Uses

type PipelineOverride struct {
    Pipeline         string            `json:"pipeline,omitempty"`
    Stage            string            `json:"stage,omitempty"`
    Name             string            `json:"name,omitempty"`
    Step             *Step             `json:"step,omitempty"`
    Steps            []*Step           `json:"steps,omitempty"`
    Type             *StepOverrideType `json:"type,omitempty"`
    Agent            *Agent            `json:"agent,omitempty"`
    ContainerOptions *corev1.Container `json:"containerOptions,omitempty"`
    Volumes          []*corev1.Volume  `json:"volumes,omitempty"`
}

PipelineOverride allows for overriding named steps, stages, or pipelines in the build pack or default pipeline

func (*PipelineOverride) AsStepsSlice Uses

func (p *PipelineOverride) AsStepsSlice() []*Step

AsStepsSlice returns a possibly empty slice of the step or steps in this override

func (*PipelineOverride) DeepCopy Uses

func (in *PipelineOverride) DeepCopy() *PipelineOverride

DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new PipelineOverride.

func (*PipelineOverride) DeepCopyInto Uses

func (in *PipelineOverride) DeepCopyInto(out *PipelineOverride)

DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil.

func (*PipelineOverride) HasNonStepOverrides Uses

func (p *PipelineOverride) HasNonStepOverrides() bool

HasNonStepOverrides returns true if this override contains configuration like agent, containerOptions, or volumes.

func (*PipelineOverride) MatchesPipeline Uses

func (p *PipelineOverride) MatchesPipeline(name string) bool

MatchesPipeline returns true if the pipeline name is specified in the override or no pipeline is specified at all in the override

func (*PipelineOverride) MatchesStage Uses

func (p *PipelineOverride) MatchesStage(name string) bool

MatchesStage returns true if the stage/lifecycle name is specified in the override or no stage/lifecycle is specified at all in the override

type Post Uses

type Post struct {
    // TODO: Conditional execution of something after a Task or Pipeline completes is not yet implemented
    Condition PostCondition `json:"condition"`
    Actions   []PostAction  `json:"actions"`
}

Post contains a PostCondition and one more actions to be executed after a pipeline or stage if the condition is met.

func (*Post) DeepCopy Uses

func (in *Post) DeepCopy() *Post

DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new Post.

func (*Post) DeepCopyInto Uses

func (in *Post) DeepCopyInto(out *Post)

DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil.

type PostAction Uses

type PostAction struct {
    // TODO: Notifications are not yet supported in Build Pipeline per se.
    Name string `json:"name"`
    // Also, we'll need to do some magic to do type verification during translation - i.e., this action wants a number
    // for this option, so translate the string value for that option to a number.
    Options map[string]string `json:"options,omitempty"`
}

PostAction contains the name of a built-in post action and options to pass to that action.

func (*PostAction) DeepCopy Uses

func (in *PostAction) DeepCopy() *PostAction

DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new PostAction.

func (*PostAction) DeepCopyInto Uses

func (in *PostAction) DeepCopyInto(out *PostAction)

DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil.

type PostCondition Uses

type PostCondition string

PostCondition is used to specify under what condition a post action should be executed.

const (
    PostConditionSuccess PostCondition = "success"
    PostConditionFailure PostCondition = "failure"
    PostConditionAlways  PostCondition = "always"
)

Probably extensible down the road

type RootOptions Uses

type RootOptions struct {
    Timeout *Timeout `json:"timeout,omitempty"`
    Retry   int8     `json:"retry,omitempty"`
    // ContainerOptions allows for advanced configuration of containers for a single stage or the whole
    // pipeline, adding to configuration that can be configured through the syntax already. This includes things
    // like CPU/RAM requests/limits, secrets, ports, etc. Some of these things will end up with native syntax approaches
    // down the road.
    ContainerOptions              *corev1.Container   `json:"containerOptions,omitempty"`
    Volumes                       []*corev1.Volume    `json:"volumes,omitempty"`
    DistributeParallelAcrossNodes bool                `json:"distributeParallelAcrossNodes,omitempty"`
    Tolerations                   []corev1.Toleration `json:"tolerations,omitempty"`
    PodLabels                     map[string]string   `json:"podLabels,omitempty"`
}

RootOptions contains options that can be configured on either a pipeline or a stage

func (*RootOptions) DeepCopy Uses

func (in *RootOptions) DeepCopy() *RootOptions

DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new RootOptions.

func (*RootOptions) DeepCopyInto Uses

func (in *RootOptions) DeepCopyInto(out *RootOptions)

DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil.

type Stage Uses

type Stage struct {
    Name       string          `json:"name"`
    Agent      *Agent          `json:"agent,omitempty"`
    Env        []corev1.EnvVar `json:"env,omitempty"`
    Options    *StageOptions   `json:"options,omitempty"`
    Steps      []Step          `json:"steps,omitempty"`
    Stages     []Stage         `json:"stages,omitempty"`
    Parallel   []Stage         `json:"parallel,omitempty"`
    Post       []Post          `json:"post,omitempty"`
    WorkingDir *string         `json:"dir,omitempty"`

    // Replaced by Env, retained for backwards compatibility
    Environment []corev1.EnvVar `json:"environment,omitempty"`
}

Stage is a unit of work in a pipeline, corresponding either to a Task or a set of Tasks to be run sequentially or in parallel with common configuration.

func ApplyNonStepOverridesToStage Uses

func ApplyNonStepOverridesToStage(stage Stage, override *PipelineOverride) Stage

ApplyNonStepOverridesToStage applies non-step overrides, such as stage agent, containerOptions, and volumes, to this stage and its children.

func ApplyStepOverridesToStage Uses

func ApplyStepOverridesToStage(stage Stage, override *PipelineOverride) Stage

ApplyStepOverridesToStage applies a set of overrides to named steps in this stage and its children

func (*Stage) DeepCopy Uses

func (in *Stage) DeepCopy() *Stage

DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new Stage.

func (*Stage) DeepCopyInto Uses

func (in *Stage) DeepCopyInto(out *Stage)

DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil.

func (*Stage) GetEnv Uses

func (s *Stage) GetEnv() []corev1.EnvVar

GetEnv gets the environment for the Stage, returning Env first and Environment if Env isn't populated.

type StageOptions Uses

type StageOptions struct {
    *RootOptions `json:",inline"`

    // TODO: Not yet implemented in build-pipeline
    Stash   *Stash   `json:"stash,omitempty"`
    Unstash *Unstash `json:"unstash,omitempty"`

    Workspace *string `json:"workspace,omitempty"`
}

StageOptions contains both options that can be configured on either a pipeline or a stage, via RootOptions, or stage-specific options.

func (*StageOptions) DeepCopy Uses

func (in *StageOptions) DeepCopy() *StageOptions

DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new StageOptions.

func (*StageOptions) DeepCopyInto Uses

func (in *StageOptions) DeepCopyInto(out *StageOptions)

DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil.

type Stash Uses

type Stash struct {
    Name string `json:"name"`
    // Eventually make this optional so that you can do volumes instead
    Files string `json:"files"`
}

Stash defines files to be saved for use in a later stage, marked with a name

func (*Stash) DeepCopy Uses

func (in *Stash) DeepCopy() *Stash

DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new Stash.

func (*Stash) DeepCopyInto Uses

func (in *Stash) DeepCopyInto(out *Stash)

DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil.

type Step Uses

type Step struct {
    // An optional name to give the step for reporting purposes
    Name string `json:"name,omitempty"`

    // One of command, step, or loop is required.
    Command string `json:"command,omitempty"`
    // args is optional, but only allowed with command
    Arguments []string `json:"args,omitempty"`
    // dir is optional, but only allowed with command. Refers to subdirectory of workspace
    Dir string `json:"dir,omitempty"`

    Step string `json:"step,omitempty"`
    // options is optional, but only allowed with step
    // Also, we'll need to do some magic to do type verification during translation - i.e., this step wants a number
    // for this option, so translate the string value for that option to a number.
    Options map[string]string `json:"options,omitempty"`

    Loop *Loop `json:"loop,omitempty"`

    // agent can be overridden on a step
    Agent *Agent `json:"agent,omitempty"`

    // Image alows the docker image for a step to be specified
    Image string `json:"image,omitempty"`

    // env allows defining per-step environment variables
    Env []corev1.EnvVar `json:"env,omitempty"`

    // Legacy fields from jenkinsfile.PipelineStep before it was eliminated.
    Comment   string  `json:"comment,omitempty"`
    Groovy    string  `json:"groovy,omitempty"`
    Steps     []*Step `json:"steps,omitempty"`
    When      string  `json:"when,omitempty"`
    Container string  `json:"container,omitempty"`
    Sh        string  `json:"sh,omitempty"`
}

Step defines a single step, from the author's perspective, to be executed within a stage.

func OverrideStep Uses

func OverrideStep(step Step, override *PipelineOverride) []Step

OverrideStep overrides an existing step, if it matches the override's name, with the contents of the override. It also recurses into child steps.

func (*Step) DeepCopy Uses

func (in *Step) DeepCopy() *Step

DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new Step.

func (*Step) DeepCopyInto Uses

func (in *Step) DeepCopyInto(out *Step)

DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil.

func (*Step) GetCommand Uses

func (s *Step) GetCommand() string

GetCommand gets the step's command to execute, opting for Command if set, then Sh.

func (*Step) GetFullCommand Uses

func (s *Step) GetFullCommand() string

GetFullCommand gets the full command to execute, including arguments.

func (*Step) GetImage Uses

func (s *Step) GetImage() string

GetImage gets the step's image to run on, opting for Image if set, then Container.

func (*Step) GroovyBlock Uses

func (s *Step) GroovyBlock(parentIndent string) string

GroovyBlock returns the groovy expression for this step Legacy code for Jenkinsfile generation

func (*Step) PutAllEnvVars Uses

func (s *Step) PutAllEnvVars(m map[string]string)

PutAllEnvVars puts all the defined environment variables in the given map Legacy code for Jenkinsfile generation

func (*Step) ToJenkinsfileStatements Uses

func (s *Step) ToJenkinsfileStatements() []*util.Statement

ToJenkinsfileStatements converts the step to one or more jenkinsfile statements Legacy code for Jenkinsfile generation

func (*Step) Validate Uses

func (s *Step) Validate() error

Validate validates the step is populated correctly Legacy code for Jenkinsfile generation

type StepOverrideType Uses

type StepOverrideType string

StepOverrideType is used to specify whether the existing step should be replaced (default), new step(s) should be prepended before the existing step, or new step(s) should be appended after the existing step.

const (
    StepOverrideReplace StepOverrideType = "replace"
    StepOverrideBefore  StepOverrideType = "before"
    StepOverrideAfter   StepOverrideType = "after"
)

The available override types

type Timeout Uses

type Timeout struct {
    Time int64 `json:"time"`
    // Has some sane default - probably seconds
    Unit TimeoutUnit `json:"unit,omitempty"`
}

Timeout defines how long a stage or pipeline can run before timing out.

func (*Timeout) DeepCopy Uses

func (in *Timeout) DeepCopy() *Timeout

DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new Timeout.

func (*Timeout) DeepCopyInto Uses

func (in *Timeout) DeepCopyInto(out *Timeout)

DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil.

func (*Timeout) ToDuration Uses

func (t *Timeout) ToDuration() (*metav1.Duration, error)

ToDuration generates a duration struct from a Timeout

type TimeoutUnit Uses

type TimeoutUnit string

TimeoutUnit is used for calculating timeout duration

const (
    TimeoutUnitSeconds TimeoutUnit = "seconds"
    TimeoutUnitMinutes TimeoutUnit = "minutes"
    TimeoutUnitHours   TimeoutUnit = "hours"
    TimeoutUnitDays    TimeoutUnit = "days"
)

The available time units.

type Unstash Uses

type Unstash struct {
    Name string `json:"name"`
    Dir  string `json:"dir,omitempty"`
}

Unstash defines a previously-defined stash to be copied into this stage's workspace

func (*Unstash) DeepCopy Uses

func (in *Unstash) DeepCopy() *Unstash

DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new Unstash.

func (*Unstash) DeepCopyInto Uses

func (in *Unstash) DeepCopyInto(out *Unstash)

DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil.

Directories

PathSynopsis
syntax_helpers_test

Package syntax imports 23 packages (graph) and is imported by 9 packages. Updated 2019-11-21. Refresh now. Tools for package owners.