Back to godoc.org
github.com/jenkins-x/jx / pkg / jenkinsfile

package jenkinsfile

v1.3.1119
Latest Go to latest
Published: Apr 15, 2019 | License: Apache-2.0 | Module: github.com/jenkins-x/jx

Index

Constants

const (
	// Name Jenkinsifile name
	Name = "Jenkinsfile"

	// BackupSuffix the suffix used by Jenkins for backups
	BackupSuffix = ".backup"
)
const (
	// PipelineConfigFileName is the name of the pipeline configuration file
	PipelineConfigFileName = "pipeline.yaml"

	// PipelineTemplateFileName defines the jenkisnfile template used to generate the pipeline
	PipelineTemplateFileName = "Jenkinsfile.tmpl"

	// PipelineKindRelease represents a release pipeline triggered on merge to master (or a release branch)
	PipelineKindRelease = "release"

	// PipelineKindPullRequest represents a Pull Request pipeline
	PipelineKindPullRequest = "pullrequest"

	// PipelineKindFeature represents a pipeline on a feature branch
	PipelineKindFeature = "feature"

	// CreateStepModePre creates steps before any existing steps
	CreateStepModePre = "pre"

	// CreateStepModePost creates steps after the existing steps
	CreateStepModePost = "post"

	// CreateStepModeReplace replaces the existing steps with the new steps
	CreateStepModeReplace = "replace"
)
const (
	// ModuleFileName the name of the module imports file name
	ModuleFileName = "imports.yaml"
)

Variables

var (
	// PipelineKinds the possible values of pipeline
	PipelineKinds = []string{PipelineKindRelease, PipelineKindPullRequest, PipelineKindFeature}

	// PipelineLifecycleNames the possible names of lifecycles of pipeline
	PipelineLifecycleNames = []string{"setup", "setversion", "prebuild", "build", "postbuild", "promote"}

	// CreateStepModes the step creation modes
	CreateStepModes = []string{CreateStepModePre, CreateStepModePost, CreateStepModeReplace}
)

func WriteJenkinsfileStatements

func WriteJenkinsfileStatements(indentCount int, statements []*Statement) string

WriteJenkinsfileStatements writes the given Jenkinsfile statements as a string

type CreateJenkinsfileArguments

type CreateJenkinsfileArguments struct {
	ConfigFile          string
	TemplateFile        string
	OutputFile          string
	JenkinsfileRunner   bool
	ClearContainerNames bool
}

CreateJenkinsfileArguments contains the arguents to generate a Jenkinsfiles dynamically

func (*CreateJenkinsfileArguments) GenerateJenkinsfile

func (a *CreateJenkinsfileArguments) GenerateJenkinsfile(resolver ImportFileResolver) error

GenerateJenkinsfile generates the jenkinsfile

func (*CreateJenkinsfileArguments) Validate

func (a *CreateJenkinsfileArguments) Validate() error

Validate validates all the arguments are set correctly

type ImportFile

type ImportFile struct {
	Import string
	File   string
}

ImportFile represents an import of a file from a module (usually a version of a git repo)

type ImportFileResolver

type ImportFileResolver func(importFile *ImportFile) (string, error)

ImportFileResolver resolves a build pack file resolver strategy

type Module

type Module struct {
	Name   string `json:"name,omitempty"`
	GitURL string `json:"gitUrl,omitempty"`
	GitRef string `json:"gitRef,omitempty"`
}

Module defines a dependent module for a build pack

func (*Module) Validate

func (m *Module) Validate() error

Validate returns an error if any data is missing

type Modules

type Modules struct {
	Modules []*Module `json:"modules,omitempty"`
}

Modules defines the dependent modules for a build pack

type NamedLifecycle

type NamedLifecycle struct {
	Name      string
	Lifecycle *PipelineLifecycle
}

NamedLifecycle a lifecycle and its name

func (*NamedLifecycle) Groovy

func (l *NamedLifecycle) Groovy() string

Groovy returns the groovy expression for this lifecycle

type PipelineAgent

type PipelineAgent struct {
	Label     string `json:"label,omitempty"`
	Container string `json:"container,omitempty"`
	Dir       string `json:"dir,omitempty"`
}

PipelineAgent contains the agent definition metadata

func (*PipelineAgent) Groovy

func (a *PipelineAgent) Groovy() string

Groovy returns the agent groovy expression for the agent or `any` if its black

type PipelineConfig

type PipelineConfig struct {
	Extends     *PipelineExtends `json:"extends,omitempty"`
	Agent       PipelineAgent    `json:"agent,omitempty"`
	Env         []corev1.EnvVar  `json:"env,omitempty"`
	Environment string           `json:"environment,omitempty"`
	Pipelines   Pipelines        `json:"pipelines,omitempty"`
}

PipelineConfig defines the pipeline configuration

func LoadPipelineConfig

func LoadPipelineConfig(fileName string, resolver ImportFileResolver, jenkinsfileRunner bool, clearContainer bool) (*PipelineConfig, error)

LoadPipelineConfig returns the pipeline configuration

func (*PipelineConfig) ExtendPipeline

func (c *PipelineConfig) ExtendPipeline(base *PipelineConfig, clearContainer bool) error

ExtendPipeline inherits this pipeline from the given base pipeline

func (*PipelineConfig) IsEmpty

func (c *PipelineConfig) IsEmpty() bool

IsEmpty returns true if this configuration is empty

func (*PipelineConfig) SaveConfig

func (c *PipelineConfig) SaveConfig(fileName string) error

SaveConfig saves the configuration file to the given project directory

type PipelineExtends

type PipelineExtends struct {
	Import string `json:"import,omitempty"`
	File   string `json:"file,omitempty"`
}

PipelineExtends defines the extension (e.g. parent pipeline which is overloaded

func (*PipelineExtends) ImportFile

func (x *PipelineExtends) ImportFile() *ImportFile

ImportFile returns an ImportFile for the given extension

type PipelineLifecycle

type PipelineLifecycle struct {
	Steps []*PipelineStep `json:"steps,omitempty"`

	// PreSteps if using inheritance then invoke these steps before the base steps
	PreSteps []*PipelineStep `json:"preSteps,omitempty"`

	// Replace if using inheritance then replace steps from the base pipeline
	Replace bool `json:"replace,omitempty"`
}

PipelineLifecycle defines the steps of a lifecycle section

func ExtendLifecycle

func ExtendLifecycle(parent *PipelineLifecycle, base *PipelineLifecycle) *PipelineLifecycle

ExtendLifecycle extends the lifecycle with the inherited base lifecycle

func (*PipelineLifecycle) CreateStep

func (l *PipelineLifecycle) CreateStep(mode string, step *PipelineStep) error

CreateStep creates the given step using the mode

func (*PipelineLifecycle) Groovy

func (l *PipelineLifecycle) Groovy() string

Groovy returns the groovy expression for this lifecycle

func (*PipelineLifecycle) RemoveWhenStatements

func (l *PipelineLifecycle) RemoveWhenStatements(prow bool)

RemoveWhenStatements removes any when conditions

func (*PipelineLifecycle) ToJenkinsfileStatements

func (l *PipelineLifecycle) ToJenkinsfileStatements() []*Statement

ToJenkinsfileStatements converts the lifecycle to one or more jenkinsfile statements

type PipelineLifecycleArray

type PipelineLifecycleArray []NamedLifecycle

PipelineLifecycleArray an array of named lifecycle pointers

func (PipelineLifecycleArray) Groovy

func (s PipelineLifecycleArray) Groovy() string

Groovy returns the groovy string for the lifecycles

type PipelineLifecycles

type PipelineLifecycles struct {
	Setup      *PipelineLifecycle     `json:"setup,omitempty"`
	SetVersion *PipelineLifecycle     `json:"setVersion,omitempty"`
	PreBuild   *PipelineLifecycle     `json:"preBuild,omitempty"`
	Build      *PipelineLifecycle     `json:"build,omitempty"`
	PostBuild  *PipelineLifecycle     `json:"postBuild,omitempty"`
	Promote    *PipelineLifecycle     `json:"promote,omitempty"`
	Pipeline   *syntax.ParsedPipeline `json:"pipeline,omitempty"`
}

PipelineLifecycles defines the steps of a lifecycle section

func ExtendPipelines

func ExtendPipelines(parent *PipelineLifecycles, base *PipelineLifecycles) *PipelineLifecycles

ExtendPipelines extends the parent lifecycle with the base

func (*PipelineLifecycles) All

func (a *PipelineLifecycles) All() PipelineLifecycleArray

All returns all lifecycles in order

func (*PipelineLifecycles) AllButPromote

func (a *PipelineLifecycles) AllButPromote() PipelineLifecycleArray

AllButPromote returns all lifecycles but promote

func (*PipelineLifecycles) GetLifecycle

func (a *PipelineLifecycles) GetLifecycle(name string, lazyCreate bool) (*PipelineLifecycle, error)

GetLifecycle returns the pipeline lifecycle of the given name lazy creating on the fly if required or returns an error if the name is not valid

func (*PipelineLifecycles) Groovy

func (a *PipelineLifecycles) Groovy() string

Groovy returns the groovy expression for all of the lifecycles

func (*PipelineLifecycles) RemoveWhenStatements

func (a *PipelineLifecycles) RemoveWhenStatements(prow bool)

RemoveWhenStatements removes any when conditions

type PipelineStep

type PipelineStep struct {
	Name      string          `json:"name,omitempty"`
	Comment   string          `json:"comment,omitempty"`
	Container string          `json:"container,omitempty"`
	Dir       string          `json:"dir,omitempty"`
	Command   string          `json:"sh,omitempty"`
	Groovy    string          `json:"groovy,omitempty"`
	Steps     []*PipelineStep `json:"steps,omitempty"`
	When      string          `json:"when,omitempty"`
}

PipelineStep defines an individual step in a pipeline, either a command (sh) or groovy block

func (*PipelineStep) GroovyBlock

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

GroovyBlock returns the groovy expression for this step

func (*PipelineStep) ToJenkinsfileStatements

func (s *PipelineStep) ToJenkinsfileStatements() []*Statement

ToJenkinsfileStatements converts the step to one or more jenkinsfile statements

func (*PipelineStep) Validate

func (s *PipelineStep) Validate() error

Validate validates the step is populated correctly

type Pipelines

type Pipelines struct {
	PullRequest *PipelineLifecycles `json:"pullRequest,omitempty"`
	Release     *PipelineLifecycles `json:"release,omitempty"`
	Feature     *PipelineLifecycles `json:"feature,omitempty"`
	Post        *PipelineLifecycle  `json:"post,omitempty"`
}

Pipelines contains all the different kinds of pipeline for different branches

func (*Pipelines) All

func (p *Pipelines) All() []*PipelineLifecycles

All returns all the lifecycles in this pipeline, some may be null

func (*Pipelines) AllMap

func (p *Pipelines) AllMap() map[string]*PipelineLifecycles

AllMap returns all the lifecycles in this pipeline indexed by the pipeline name

func (*Pipelines) Extend

func (p *Pipelines) Extend(base *Pipelines) error

Extend extends these pipelines with the base pipeline

func (*Pipelines) GetPipeline

func (p *Pipelines) GetPipeline(kind string, lazyCreate bool) (*PipelineLifecycles, error)

GetPipeline returns the pipeline for the given name, creating if required if lazyCreate is true or returns an error if its not a valid name

func (*Pipelines) RemoveWhenStatements

func (p *Pipelines) RemoveWhenStatements(prow bool)

RemoveWhenStatements removes any prow or !prow statements

type Statement

type Statement struct {
	Function  string
	Arguments []string
	Statement string
	Children  []*Statement
}

Statement represents a statement in a Jenkinsfile

func (*Statement) ContextEquals

func (s *Statement) ContextEquals(that *Statement) bool

ContextEquals returns true if this statement is a context statement and it equals the same context as that statement

func (*Statement) Text

func (s *Statement) Text() string

Text returns the text line of the current function or statement

type Writer

type Writer struct {
	InitialIndent string
	IndentText    string
	Buffer        bytes.Buffer
	IndentCount   int
}

Writer implements the struct for Jenkinsfilewriter

func NewWriter

func NewWriter(indentCount int) *Writer

NewWriter creates a Jenkinsfile writer

func (*Writer) String

func (w *Writer) String() string

String returns the string value of this writer

func (*Writer) Write

func (w *Writer) Write(inputStatements []*Statement)
Documentation was rendered with GOOS=linux and GOARCH=amd64.

Jump to identifier

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to identifier