pipeline

package
v1.3.0 Latest Latest
Warning

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

Go to latest
Published: Jan 12, 2026 License: MIT Imports: 1 Imported by: 0

Documentation

Overview

Package pipeline provides core types for GitLab CI/CD pipeline definitions.

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type AllowFailure

type AllowFailure struct {
	Allow     bool  `yaml:"-" json:"-"`
	ExitCodes []int `yaml:"exit_codes,omitempty" json:"exit_codes,omitempty"`
}

AllowFailure defines the allow_failure configuration for a job. It can be a simple boolean or include specific exit codes.

func (AllowFailure) IsZero

func (a AllowFailure) IsZero() bool

IsZero returns true if AllowFailure is empty.

type Artifacts

type Artifacts struct {
	Paths     []string `yaml:"paths,omitempty" json:"paths,omitempty"`
	Exclude   []string `yaml:"exclude,omitempty" json:"exclude,omitempty"`
	ExpireIn  string   `yaml:"expire_in,omitempty" json:"expire_in,omitempty"`
	Name      string   `yaml:"name,omitempty" json:"name,omitempty"`
	When      string   `yaml:"when,omitempty" json:"when,omitempty"`
	Untracked bool     `yaml:"untracked,omitempty" json:"untracked,omitempty"`
	Reports   Reports  `yaml:"reports,omitempty" json:"reports,omitempty"`
}

Artifacts defines artifact configuration for a job.

func (Artifacts) IsZero

func (a Artifacts) IsZero() bool

IsZero returns true if Artifacts is empty.

type AssetLink struct {
	Name     string `yaml:"name,omitempty" json:"name,omitempty"`
	URL      string `yaml:"url,omitempty" json:"url,omitempty"`
	FilePath string `yaml:"filepath,omitempty" json:"filepath,omitempty"`
	LinkType string `yaml:"link_type,omitempty" json:"link_type,omitempty"`
}

AssetLink defines a release asset link.

func (AssetLink) IsZero

func (al AssetLink) IsZero() bool

IsZero returns true if AssetLink is empty.

type Assets

type Assets struct {
	Links []AssetLink `yaml:"links,omitempty" json:"links,omitempty"`
}

Assets defines release assets.

func (Assets) IsZero

func (a Assets) IsZero() bool

IsZero returns true if Assets is empty.

type AutoCancel

type AutoCancel struct {
	OnNewCommit  string `yaml:"on_new_commit,omitempty" json:"on_new_commit,omitempty"`
	OnJobFailure string `yaml:"on_job_failure,omitempty" json:"on_job_failure,omitempty"`
}

AutoCancel defines auto-cancellation behavior for pipelines.

func (AutoCancel) IsZero

func (a AutoCancel) IsZero() bool

IsZero returns true if AutoCancel is empty.

type Cache

type Cache struct {
	Key          any      `yaml:"key,omitempty" json:"key,omitempty"`
	Paths        []string `yaml:"paths,omitempty" json:"paths,omitempty"`
	FallbackKeys []string `yaml:"fallback_keys,omitempty" json:"fallback_keys,omitempty"`
	Policy       string   `yaml:"policy,omitempty" json:"policy,omitempty"`
	Untracked    bool     `yaml:"untracked,omitempty" json:"untracked,omitempty"`
	When         string   `yaml:"when,omitempty" json:"when,omitempty"`
}

Cache defines cache configuration for a job.

Example

ExampleCache demonstrates using cache to speed up builds.

buildJob := pipeline.Job{
	Name:   "build",
	Stage:  "build",
	Script: List("go build ./..."),
	Cache: pipeline.Cache{
		Key: "go-cache",
		Paths: List(
			".go/pkg/mod",
			".cache/go-build",
		),
		Policy: string(Pull),
	},
}

data, _ := yaml.Marshal(map[string]any{
	buildJob.Name: buildJob,
})
fmt.Println(string(data))
Output:

build:
    stage: build
    script:
        - go build ./...
    cache:
        key: go-cache
        paths:
            - .go/pkg/mod
            - .cache/go-build
        policy: pull

func (Cache) IsZero

func (c Cache) IsZero() bool

IsZero returns true if Cache is empty.

type CacheKey

type CacheKey struct {
	Files  []string `yaml:"files,omitempty" json:"files,omitempty"`
	Prefix string   `yaml:"prefix,omitempty" json:"prefix,omitempty"`
}

CacheKey defines a dynamic cache key based on files.

func (CacheKey) IsZero

func (ck CacheKey) IsZero() bool

IsZero returns true if CacheKey is empty.

type Default

type Default struct {
	Image         Image     `yaml:"image,omitempty" json:"image,omitempty"`
	Services      []Service `yaml:"services,omitempty" json:"services,omitempty"`
	BeforeScript  []string  `yaml:"before_script,omitempty" json:"before_script,omitempty"`
	AfterScript   []string  `yaml:"after_script,omitempty" json:"after_script,omitempty"`
	Tags          []string  `yaml:"tags,omitempty" json:"tags,omitempty"`
	Cache         Cache     `yaml:"cache,omitempty" json:"cache,omitempty"`
	Artifacts     Artifacts `yaml:"artifacts,omitempty" json:"artifacts,omitempty"`
	Retry         int       `yaml:"retry,omitempty" json:"retry,omitempty"`
	Timeout       string    `yaml:"timeout,omitempty" json:"timeout,omitempty"`
	Interruptible bool      `yaml:"interruptible,omitempty" json:"interruptible,omitempty"`
}

Default defines default values inherited by all jobs.

func (Default) IsZero

func (d Default) IsZero() bool

IsZero returns true if Default is empty.

type DeploymentApproval

type DeploymentApproval struct {
	RequiredApprovals int      `yaml:"required_approvals,omitempty" json:"required_approvals,omitempty"`
	AllowedApprovers  []string `yaml:"allowed_approvers,omitempty" json:"allowed_approvers,omitempty"`
	AllowedGroups     []string `yaml:"allowed_groups,omitempty" json:"allowed_groups,omitempty"`
}

DeploymentApproval defines the deployment approval requirements for an environment. This is a GitLab 17.x feature that allows requiring approvals before deployments proceed.

Basic usage (require 2 approvals):

DeploymentApproval: pipeline.DeploymentApproval{
    RequiredApprovals: 2,
}

With specific approvers:

DeploymentApproval: pipeline.DeploymentApproval{
    RequiredApprovals: 1,
    AllowedApprovers:  []string{"user1", "user2"},
}

With group-based approvers:

DeploymentApproval: pipeline.DeploymentApproval{
    RequiredApprovals: 2,
    AllowedGroups:     []string{"security", "ops"},
}

func (DeploymentApproval) IsZero

func (d DeploymentApproval) IsZero() bool

IsZero returns true if DeploymentApproval is empty.

type Environment

type Environment struct {
	Name               string             `yaml:"name,omitempty" json:"name,omitempty"`
	URL                string             `yaml:"url,omitempty" json:"url,omitempty"`
	Action             string             `yaml:"action,omitempty" json:"action,omitempty"`
	OnStop             string             `yaml:"on_stop,omitempty" json:"on_stop,omitempty"`
	AutoStopIn         string             `yaml:"auto_stop_in,omitempty" json:"auto_stop_in,omitempty"`
	Tier               string             `yaml:"deployment_tier,omitempty" json:"deployment_tier,omitempty"`
	DeploymentApproval DeploymentApproval `yaml:"deployment_approval,omitempty" json:"deployment_approval,omitempty"`
}

Environment defines the deployment environment for a job.

func (Environment) IsZero

func (e Environment) IsZero() bool

IsZero returns true if Environment is empty.

type Forward

type Forward struct {
	YAMLVariables     bool `yaml:"yaml_variables,omitempty" json:"yaml_variables,omitempty"`
	PipelineVariables bool `yaml:"pipeline_variables,omitempty" json:"pipeline_variables,omitempty"`
}

Forward controls what variables are forwarded to downstream pipelines.

func (Forward) IsZero

func (f Forward) IsZero() bool

IsZero returns true if Forward is empty.

type Hooks

type Hooks struct {
	PreGetSourcesScript  []string `yaml:"pre_get_sources_script,omitempty" json:"pre_get_sources_script,omitempty"`
	PostGetSourcesScript []string `yaml:"post_get_sources_script,omitempty" json:"post_get_sources_script,omitempty"`
}

Hooks contains job lifecycle hook scripts. Hooks allow running scripts at specific points in the job lifecycle.

func (Hooks) IsZero

func (h Hooks) IsZero() bool

IsZero returns true if Hooks is empty.

type Image

type Image struct {
	Name       string   `yaml:"name,omitempty" json:"name,omitempty"`
	Entrypoint []string `yaml:"entrypoint,omitempty" json:"entrypoint,omitempty"`
	PullPolicy string   `yaml:"pull_policy,omitempty" json:"pull_policy,omitempty"`
}

Image defines a Docker image configuration for a job.

func (Image) IsZero

func (i Image) IsZero() bool

IsZero returns true if the Image is empty.

type Include

type Include struct {
	Local     string         `yaml:"local,omitempty" json:"local,omitempty"`
	Remote    string         `yaml:"remote,omitempty" json:"remote,omitempty"`
	Project   string         `yaml:"project,omitempty" json:"project,omitempty"`
	File      string         `yaml:"file,omitempty" json:"file,omitempty"`
	Ref       string         `yaml:"ref,omitempty" json:"ref,omitempty"`
	Template  string         `yaml:"template,omitempty" json:"template,omitempty"`
	Component string         `yaml:"component,omitempty" json:"component,omitempty"`
	Inputs    map[string]any `yaml:"inputs,omitempty" json:"inputs,omitempty"`
	Rules     []Rule         `yaml:"rules,omitempty" json:"rules,omitempty"`
}

Include defines an include directive in a GitLab CI/CD configuration. GitLab supports 6 types of includes: local, remote, project, template, component.

func (Include) IsZero

func (i Include) IsZero() bool

IsZero returns true if Include is empty.

type Inherit

type Inherit struct {
	Default   any `yaml:"default,omitempty" json:"default,omitempty"`
	Variables any `yaml:"variables,omitempty" json:"variables,omitempty"`
}

Inherit controls what global configuration is inherited by the job.

func (Inherit) IsZero

func (i Inherit) IsZero() bool

IsZero returns true if Inherit is empty.

type Job

type Job struct {
	Name               string         `yaml:"-" json:"-"`
	Stage              string         `yaml:"stage,omitempty" json:"stage,omitempty"`
	Image              Image          `yaml:"image,omitempty" json:"image,omitempty"`
	Services           []Service      `yaml:"services,omitempty" json:"services,omitempty"`
	BeforeScript       []string       `yaml:"before_script,omitempty" json:"before_script,omitempty"`
	Script             []string       `yaml:"script,omitempty" json:"script,omitempty"`
	AfterScript        []string       `yaml:"after_script,omitempty" json:"after_script,omitempty"`
	Variables          map[string]any `yaml:"variables,omitempty" json:"variables,omitempty"`
	Rules              []Rule         `yaml:"rules,omitempty" json:"rules,omitempty"`
	Only               []string       `yaml:"only,omitempty" json:"only,omitempty"`
	Except             []string       `yaml:"except,omitempty" json:"except,omitempty"`
	Tags               []string       `yaml:"tags,omitempty" json:"tags,omitempty"`
	AllowFailure       any            `yaml:"allow_failure,omitempty" json:"allow_failure,omitempty"`
	When               string         `yaml:"when,omitempty" json:"when,omitempty"`
	Environment        Environment    `yaml:"environment,omitempty" json:"environment,omitempty"`
	Cache              Cache          `yaml:"cache,omitempty" json:"cache,omitempty"`
	Artifacts          Artifacts      `yaml:"artifacts,omitempty" json:"artifacts,omitempty"`
	Dependencies       []string       `yaml:"dependencies,omitempty" json:"dependencies,omitempty"`
	Needs              []any          `yaml:"needs,omitempty" json:"needs,omitempty"`
	Extends            []any          `yaml:"extends,omitempty" json:"extends,omitempty"`
	Retry              any            `yaml:"retry,omitempty" json:"retry,omitempty"`
	Timeout            string         `yaml:"timeout,omitempty" json:"timeout,omitempty"`
	Parallel           any            `yaml:"parallel,omitempty" json:"parallel,omitempty"`
	Interruptible      bool           `yaml:"interruptible,omitempty" json:"interruptible,omitempty"`
	ResourceGroup      string         `yaml:"resource_group,omitempty" json:"resource_group,omitempty"`
	Trigger            Trigger        `yaml:"trigger,omitempty" json:"trigger,omitempty"`
	Inherit            Inherit        `yaml:"inherit,omitempty" json:"inherit,omitempty"`
	Coverage           string         `yaml:"coverage,omitempty" json:"coverage,omitempty"`
	Secrets            map[string]any `yaml:"secrets,omitempty" json:"secrets,omitempty"`
	IdTokens           map[string]any `yaml:"id_tokens,omitempty" json:"id_tokens,omitempty"`
	Release            Release        `yaml:"release,omitempty" json:"release,omitempty"`
	Pages              Pages          `yaml:"pages,omitempty" json:"pages,omitempty"`
	Hooks              Hooks          `yaml:"hooks,omitempty" json:"hooks,omitempty"`
	ManualConfirmation string         `yaml:"manual_confirmation,omitempty" json:"manual_confirmation,omitempty"`
}

Job defines a GitLab CI/CD job configuration.

Example

ExampleJob demonstrates creating a basic job with a script.

job := pipeline.Job{
	Name:   "build",
	Stage:  "build",
	Script: List("go build ./..."),
}

data, _ := yaml.Marshal(map[string]any{
	job.Name: job,
})
fmt.Println(string(data))
Output:

build:
    stage: build
    script:
        - go build ./...
Example (WithArtifacts)

ExampleJob_withArtifacts demonstrates a job that produces artifacts.

job := pipeline.Job{
	Name:   "test",
	Stage:  "test",
	Script: List("go test -v -coverprofile=coverage.out ./..."),
	Artifacts: pipeline.Artifacts{
		Paths:    List("coverage.out"),
		ExpireIn: "1 week",
		Reports: pipeline.Reports{
			Cobertura: "coverage.out",
		},
	},
}

data, _ := yaml.Marshal(map[string]any{
	job.Name: job,
})
fmt.Println(string(data))
Output:

test:
    stage: test
    script:
        - go test -v -coverprofile=coverage.out ./...
    artifacts:
        paths:
            - coverage.out
        expire_in: 1 week
        reports:
            cobertura: coverage.out

func (Job) IsZero

func (j Job) IsZero() bool

IsZero returns true if Job is empty (has no name).

type JobRef

type JobRef struct {
	Job       any  `json:"job,omitempty"`
	Artifacts bool `json:"artifacts,omitempty"`
	Optional  bool `json:"optional,omitempty"`
}

JobRef represents a reference to another job for needs/dependencies. Use JobRef when you need to specify additional options like artifacts or optional flags.

Basic usage (job variable reference):

Needs: []any{BuildJob}

With artifacts (download artifacts from the referenced job):

Needs: []any{JobRef{Job: BuildJob, Artifacts: true}}

Optional dependency (don't fail if the job doesn't exist):

Needs: []any{JobRef{Job: OptionalJob, Optional: true}}

String reference (for external/component jobs):

Needs: []any{JobRef{Job: "sast", Optional: true}}

func (JobRef) IsZero

func (r JobRef) IsZero() bool

IsZero returns true if JobRef is empty (has no job).

func (JobRef) MarshalJSON

func (r JobRef) MarshalJSON() ([]byte, error)

MarshalJSON serializes JobRef to GitLab CI needs format. Simple references are serialized as strings, complex ones as objects.

type Pages

type Pages struct {
	PathPrefix string `yaml:"path_prefix,omitempty" json:"path_prefix,omitempty"`
}

Pages defines GitLab Pages configuration.

func (Pages) IsZero

func (p Pages) IsZero() bool

IsZero returns true if Pages is empty.

type Parallel

type Parallel struct {
	// Matrix defines build matrix dimensions for parallel job execution.
	// Each map in the slice represents a matrix row with variable names as keys
	// and their possible values as slices.
	//
	// Example:
	//   Matrix: []map[string][]string{
	//       {
	//           "PROVIDER": {"aws", "gcp"},
	//           "STACK":    {"monitoring", "backup"},
	//       },
	//       {
	//           "PROVIDER": {"vultr"},
	//           "STACK":    {"monitoring"},
	//       },
	//   }
	//
	// This creates parallel jobs for each combination:
	// - aws + monitoring, aws + backup
	// - gcp + monitoring, gcp + backup
	// - vultr + monitoring
	Matrix []map[string][]string `yaml:"matrix,omitempty" json:"matrix,omitempty"`
}

Parallel defines parallel job execution configuration. It supports both simple parallel count and matrix-based parallel execution.

For simple parallel execution with a count, use an integer:

job := Job{
    Name:     "test",
    Script:   List("go test ./..."),
    Parallel: 5,  // Runs 5 parallel instances
}

For matrix-based parallel execution, use the Parallel struct:

job := Job{
    Name:   "test-matrix",
    Script: List("go test ./..."),
    Parallel: Parallel{
        Matrix: []map[string][]string{
            {
                "VERSION":  {"1.21", "1.22", "1.23"},
                "PLATFORM": {"linux", "darwin"},
            },
        },
    },
}

This generates a job for each combination of VERSION and PLATFORM.

Example (Count)

ExampleParallel_count demonstrates using a simple parallel count

job := pipeline.Job{
	Name:     "test",
	Script:   []string{"go test ./..."},
	Parallel: 5, // Runs 5 parallel instances
}

data, _ := yaml.Marshal(map[string]any{
	"test-job": map[string]any{
		"script":   job.Script,
		"parallel": job.Parallel,
	},
})

fmt.Println(string(data))
Output:

test-job:
    parallel: 5
    script:
        - go test ./...
Example (Matrix)

ExampleParallel_matrix demonstrates using matrix for parallel builds

job := pipeline.Job{
	Name:  "test-matrix",
	Stage: "test",
	Script: []string{
		"echo Testing Go $GO_VERSION",
		"go test ./...",
	},
	Parallel: pipeline.Parallel{
		Matrix: []map[string][]string{
			{
				"GO_VERSION": {"1.22", "1.23"},
				"PLATFORM":   {"linux", "darwin"},
			},
		},
	},
}

data, _ := yaml.Marshal(map[string]any{
	"test-matrix": map[string]any{
		"stage":    job.Stage,
		"script":   job.Script,
		"parallel": job.Parallel,
	},
})

fmt.Println(string(data))
Output:

test-matrix:
    parallel:
        matrix:
            - GO_VERSION:
                - "1.22"
                - "1.23"
              PLATFORM:
                - linux
                - darwin
    script:
        - echo Testing Go $GO_VERSION
        - go test ./...
    stage: test
Example (MultipleMatrixRows)

ExampleParallel_multipleMatrixRows demonstrates multiple matrix configurations

job := pipeline.Job{
	Name:  "deploy-stacks",
	Stage: "deploy",
	Script: []string{
		"echo Deploying $STACK to $PROVIDER",
		"./deploy.sh",
	},
	Parallel: pipeline.Parallel{
		Matrix: []map[string][]string{
			{
				"PROVIDER": {"aws"},
				"STACK":    {"monitoring", "app1", "app2"},
			},
			{
				"PROVIDER": {"gcp", "vultr"},
				"STACK":    {"data", "processing"},
			},
		},
	},
	Environment: pipeline.Environment{
		Name: "$PROVIDER/$STACK",
	},
}

data, _ := yaml.Marshal(map[string]any{
	"deploy-stacks": map[string]any{
		"stage":    job.Stage,
		"script":   job.Script,
		"parallel": job.Parallel,
		"environment": map[string]any{
			"name": job.Environment.Name,
		},
	},
})

fmt.Println(string(data))
Output:

deploy-stacks:
    environment:
        name: $PROVIDER/$STACK
    parallel:
        matrix:
            - PROVIDER:
                - aws
              STACK:
                - monitoring
                - app1
                - app2
            - PROVIDER:
                - gcp
                - vultr
              STACK:
                - data
                - processing
    script:
        - echo Deploying $STACK to $PROVIDER
        - ./deploy.sh
    stage: deploy

func (Parallel) IsZero

func (p Parallel) IsZero() bool

IsZero returns true if Parallel is empty.

type Pipeline

type Pipeline struct {
	Stages    []string       `yaml:"stages,omitempty" json:"stages,omitempty"`
	Include   []Include      `yaml:"include,omitempty" json:"include,omitempty"`
	Default   Default        `yaml:"default,omitempty" json:"default,omitempty"`
	Variables map[string]any `yaml:"variables,omitempty" json:"variables,omitempty"`
	Workflow  Workflow       `yaml:"workflow,omitempty" json:"workflow,omitempty"`
}

Pipeline defines the top-level GitLab CI/CD pipeline configuration.

Example

ExamplePipeline demonstrates a full pipeline with multiple stages and jobs.

buildJob := pipeline.Job{
	Name:   "build",
	Stage:  "build",
	Script: List("go build ./..."),
}

testJob := pipeline.Job{
	Name:   "test",
	Stage:  "test",
	Script: List("go test ./..."),
	Needs:  []any{"build"},
}

deployJob := pipeline.Job{
	Name:   "deploy",
	Stage:  "deploy",
	Script: List("./deploy.sh"),
	Rules:  List(OnDefaultBranch),
	Needs:  []any{"test"},
}

p := pipeline.Pipeline{
	Stages: List("build", "test", "deploy"),
	Variables: Json{
		"GOVERSION": "1.23",
	},
}

// Combine pipeline and jobs
output := map[string]any{
	"stages":       p.Stages,
	"variables":    p.Variables,
	buildJob.Name:  buildJob,
	testJob.Name:   testJob,
	deployJob.Name: deployJob,
}

data, _ := yaml.Marshal(output)
fmt.Println(string(data))
Output:

build:
    stage: build
    script:
        - go build ./...
deploy:
    stage: deploy
    script:
        - ./deploy.sh
    rules:
        - if: $CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH
    needs:
        - test
stages:
    - build
    - test
    - deploy
test:
    stage: test
    script:
        - go test ./...
    needs:
        - build
variables:
    GOVERSION: "1.23"

func (Pipeline) IsZero

func (p Pipeline) IsZero() bool

IsZero returns true if Pipeline is empty.

type Release

type Release struct {
	TagName     string   `yaml:"tag_name,omitempty" json:"tag_name,omitempty"`
	TagMessage  string   `yaml:"tag_message,omitempty" json:"tag_message,omitempty"`
	Name        string   `yaml:"name,omitempty" json:"name,omitempty"`
	Description string   `yaml:"description,omitempty" json:"description,omitempty"`
	Ref         string   `yaml:"ref,omitempty" json:"ref,omitempty"`
	Milestones  []string `yaml:"milestones,omitempty" json:"milestones,omitempty"`
	ReleasedAt  string   `yaml:"released_at,omitempty" json:"released_at,omitempty"`
	Assets      Assets   `yaml:"assets,omitempty" json:"assets,omitempty"`
}

Release defines release configuration for a job.

func (Release) IsZero

func (r Release) IsZero() bool

IsZero returns true if Release is empty.

type Reports

type Reports struct {
	JUnit           []string `yaml:"junit,omitempty" json:"junit,omitempty"`
	Coverage        string   `yaml:"coverage_report,omitempty" json:"coverage_report,omitempty"`
	Cobertura       string   `yaml:"cobertura,omitempty" json:"cobertura,omitempty"`
	Codequality     string   `yaml:"codequality,omitempty" json:"codequality,omitempty"`
	SAST            string   `yaml:"sast,omitempty" json:"sast,omitempty"`
	DependencyScan  string   `yaml:"dependency_scanning,omitempty" json:"dependency_scanning,omitempty"`
	ContainerScan   string   `yaml:"container_scanning,omitempty" json:"container_scanning,omitempty"`
	DAST            string   `yaml:"dast,omitempty" json:"dast,omitempty"`
	SecretDetection string   `yaml:"secret_detection,omitempty" json:"secret_detection,omitempty"`
	Terraform       string   `yaml:"terraform,omitempty" json:"terraform,omitempty"`
	Metrics         string   `yaml:"metrics,omitempty" json:"metrics,omitempty"`
	Dotenv          string   `yaml:"dotenv,omitempty" json:"dotenv,omitempty"`
}

Reports defines artifact reports configuration.

func (Reports) IsZero

func (r Reports) IsZero() bool

IsZero returns true if Reports is empty.

type Retry

type Retry struct {
	Max       int      `yaml:"max,omitempty" json:"max,omitempty"`
	When      []string `yaml:"when,omitempty" json:"when,omitempty"`
	ExitCodes []int    `yaml:"exit_codes,omitempty" json:"exit_codes,omitempty"`
}

Retry defines retry configuration for a job.

func (Retry) IsZero

func (r Retry) IsZero() bool

IsZero returns true if Retry is empty.

type Rule

type Rule struct {
	If           string            `yaml:"if,omitempty" json:"if,omitempty"`
	Changes      []string          `yaml:"changes,omitempty" json:"changes,omitempty"`
	Exists       []string          `yaml:"exists,omitempty" json:"exists,omitempty"`
	When         string            `yaml:"when,omitempty" json:"when,omitempty"`
	AllowFailure bool              `yaml:"allow_failure,omitempty" json:"allow_failure,omitempty"`
	Variables    map[string]string `yaml:"variables,omitempty" json:"variables,omitempty"`
}

Rule defines a rule for when a job should run.

Example

ExampleRule demonstrates using rules to control when a job runs.

deployJob := pipeline.Job{
	Name:   "deploy",
	Stage:  "deploy",
	Script: List("./deploy.sh"),
	Rules: List(
		OnDefaultBranch,
		OnTag,
	),
}

data, _ := yaml.Marshal(map[string]any{
	deployJob.Name: deployJob,
})
fmt.Println(string(data))
Output:

deploy:
    stage: deploy
    script:
        - ./deploy.sh
    rules:
        - if: $CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH
        - if: $CI_COMMIT_TAG

func (Rule) IsZero

func (r Rule) IsZero() bool

IsZero returns true if Rule is empty.

type Service

type Service struct {
	Name       string            `yaml:"name,omitempty" json:"name,omitempty"`
	Alias      string            `yaml:"alias,omitempty" json:"alias,omitempty"`
	Entrypoint []string          `yaml:"entrypoint,omitempty" json:"entrypoint,omitempty"`
	Command    []string          `yaml:"command,omitempty" json:"command,omitempty"`
	Variables  map[string]string `yaml:"variables,omitempty" json:"variables,omitempty"`
	PullPolicy string            `yaml:"pull_policy,omitempty" json:"pull_policy,omitempty"`
}

Service defines a service container for a job.

Example

ExampleService demonstrates how to define services for a job. Services are Docker containers that run alongside the job and provide additional functionality like databases or caches.

postgresService := pipeline.Service{
	Name:  "postgres:16",
	Alias: "db",
	Variables: map[string]string{
		"POSTGRES_DB":       "test_db",
		"POSTGRES_USER":     "test_user",
		"POSTGRES_PASSWORD": "test_pass",
	},
}

redisService := pipeline.Service{
	Name:    "redis:7-alpine",
	Alias:   "cache",
	Command: List("--maxmemory", "256mb"),
}

testJob := pipeline.Job{
	Name:   "integration-test",
	Stage:  "test",
	Script: List("go test -tags=integration ./..."),
	Services: List(
		postgresService,
		redisService,
	),
	Variables: Json{
		"DATABASE_URL": "postgres://test_user:test_pass@db:5432/test_db",
		"REDIS_URL":    "redis://cache:6379",
	},
}

data, _ := yaml.Marshal(map[string]any{
	testJob.Name: testJob,
})
fmt.Println(string(data))
Output:

integration-test:
    stage: test
    services:
        - name: postgres:16
          alias: db
          variables:
            POSTGRES_DB: test_db
            POSTGRES_PASSWORD: test_pass
            POSTGRES_USER: test_user
        - name: redis:7-alpine
          alias: cache
          command:
            - --maxmemory
            - 256mb
    script:
        - go test -tags=integration ./...
    variables:
        DATABASE_URL: postgres://test_user:test_pass@db:5432/test_db
        REDIS_URL: redis://cache:6379

func (Service) IsZero

func (s Service) IsZero() bool

IsZero returns true if Service is empty.

type Trigger

type Trigger struct {
	// For child pipelines
	Include  string `yaml:"include,omitempty" json:"include,omitempty"`
	Strategy string `yaml:"strategy,omitempty" json:"strategy,omitempty"`

	// For multi-project pipelines
	Project string `yaml:"project,omitempty" json:"project,omitempty"`
	Branch  string `yaml:"branch,omitempty" json:"branch,omitempty"`

	// Common options
	Forward Forward `yaml:"forward,omitempty" json:"forward,omitempty"`
}

Trigger defines a trigger for child or multi-project pipelines.

func (Trigger) IsZero

func (t Trigger) IsZero() bool

IsZero returns true if Trigger is empty.

type Workflow

type Workflow struct {
	Name       string     `yaml:"name,omitempty" json:"name,omitempty"`
	Rules      []Rule     `yaml:"rules,omitempty" json:"rules,omitempty"`
	AutoCancel AutoCancel `yaml:"auto_cancel,omitempty" json:"auto_cancel,omitempty"`
}

Workflow defines workflow rules for the entire pipeline.

func (Workflow) IsZero

func (w Workflow) IsZero() bool

IsZero returns true if Workflow is empty.

Jump to

Keyboard shortcuts

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