Skip to main content
Version: Next ๐Ÿšง

Environment variables

Woodpecker provides the ability to pass environment variables to individual pipeline steps. Note that these can't overwrite any existing, built-in variables. Example pipeline step with custom environment variables:

 steps:
- name: build
image: golang
+ environment:
+ CGO: 0
+ GOOS: linux
+ GOARCH: amd64
commands:
- go build
- go test

Please note that the environment section is not able to expand environment variables. If you need to expand variables they should be exported in the commands section.

 steps:
- name: build
image: golang
- environment:
- - PATH=$PATH:/go
commands:
+ - export PATH=$PATH:/go
- go build
- go test
warning

${variable} expressions are subject to pre-processing. If you do not want the pre-processor to evaluate your expression it must be escaped:

 steps:
- name: build
image: golang
commands:
- - export PATH=${PATH}:/go
+ - export PATH=$${PATH}:/go
- go build
- go test

Built-in environment variablesโ€‹

This is the reference list of all environment variables available to your pipeline containers. These are injected into your pipeline step and plugins containers, at runtime.

NAMEDescriptionExample
CICI environment namewoodpecker
Repository
CI_REPOrepository full name <owner>/<name>john-doe/my-repo
CI_REPO_OWNERrepository ownerjohn-doe
CI_REPO_NAMErepository namemy-repo
CI_REPO_REMOTE_IDrepository remote ID, is the UID it has in the forge82
CI_REPO_SCMrepository SCMgit
CI_REPO_URLrepository web URLhttps://git.example.com/john-doe/my-repo
CI_REPO_CLONE_URLrepository clone URLhttps://git.example.com/john-doe/my-repo.git
CI_REPO_CLONE_SSH_URLrepository SSH clone URLgit@git.example.com:john-doe/my-repo.git
CI_REPO_DEFAULT_BRANCHrepository default branchmain
CI_REPO_PRIVATErepository is privatetrue
CI_REPO_TRUSTED_NETWORKrepository has trusted network accessfalse
CI_REPO_TRUSTED_VOLUMESrepository has trusted volumes accessfalse
CI_REPO_TRUSTED_SECURITYrepository has trusted security accessfalse
Current Commit
CI_COMMIT_SHAcommit SHAeba09b46064473a1d345da7abf28b477468e8dbd
CI_COMMIT_REFcommit refrefs/heads/main
CI_COMMIT_REFSPECcommit ref specissue-branch:main
CI_COMMIT_BRANCHcommit branch (equals target branch for pull requests)main
CI_COMMIT_SOURCE_BRANCHcommit source branch (empty if event is not pull_request or pull_request_closed)issue-branch
CI_COMMIT_TARGET_BRANCHcommit target branch (empty if event is not pull_request or pull_request_closed)main
CI_COMMIT_TAGcommit tag name (empty if event is not tag)v1.10.3
CI_COMMIT_PULL_REQUESTcommit pull request number (empty if event is not pull_request or pull_request_closed)1
CI_COMMIT_PULL_REQUEST_LABELSlabels assigned to pull request (empty if event is not pull_request or pull_request_closed)server
CI_COMMIT_MESSAGEcommit messageInitial commit
CI_COMMIT_AUTHORcommit author usernamejohn-doe
CI_COMMIT_AUTHOR_EMAILcommit author email addressjohn-doe@example.com
CI_COMMIT_AUTHOR_AVATARcommit author avatarhttps://git.example.com/avatars/5dcbcadbce6f87f8abef
CI_COMMIT_PRERELEASErelease is a pre-release (empty if event is not release)false
Current pipeline
CI_PIPELINE_NUMBERpipeline number8
CI_PIPELINE_PARENTnumber of parent pipeline0
CI_PIPELINE_EVENTpipeline event (see event)push, pull_request, pull_request_closed, tag, release, manual, cron
CI_PIPELINE_URLlink to the web UI for the pipelinehttps://ci.example.com/repos/7/pipeline/8
CI_PIPELINE_FORGE_URLlink to the forge's web UI for the commit(s) or tag that triggered the pipelinehttps://git.example.com/john-doe/my-repo/commit/eba09b46064473a1d345da7abf28b477468e8dbd
CI_PIPELINE_DEPLOY_TARGETpipeline deploy target for deployment eventsproduction
CI_PIPELINE_DEPLOY_TASKpipeline deploy task for deployment eventsmigration
CI_PIPELINE_CREATEDpipeline created UNIX timestamp1722617519
CI_PIPELINE_STARTEDpipeline started UNIX timestamp1722617519
CI_PIPELINE_FILESchanged files (empty if event is not push or pull_request), it is undefined if more than 500 files are touched[], [".woodpecker.yml","README.md"]
Current workflow
CI_WORKFLOW_NAMEworkflow namerelease
Current step
CI_STEP_NAMEstep namebuild package
CI_STEP_NUMBERstep number0
CI_STEP_STARTEDstep started UNIX timestamp1722617519
CI_STEP_URLURL to step in UIhttps://ci.example.com/repos/7/pipeline/8
Previous commit
CI_PREV_COMMIT_SHAprevious commit SHA15784117e4e103f36cba75a9e29da48046eb82c4
CI_PREV_COMMIT_REFprevious commit refrefs/heads/main
CI_PREV_COMMIT_REFSPECprevious commit ref specissue-branch:main
CI_PREV_COMMIT_BRANCHprevious commit branchmain
CI_PREV_COMMIT_SOURCE_BRANCHprevious commit source branchissue-branch
CI_PREV_COMMIT_TARGET_BRANCHprevious commit target branchmain
CI_PREV_COMMIT_URLprevious commit link in forgehttps://git.example.com/john-doe/my-repo/commit/15784117e4e103f36cba75a9e29da48046eb82c4
CI_PREV_COMMIT_MESSAGEprevious commit messagetest
CI_PREV_COMMIT_AUTHORprevious commit author usernamejohn-doe
CI_PREV_COMMIT_AUTHOR_EMAILprevious commit author email addressjohn-doe@example.com
CI_PREV_COMMIT_AUTHOR_AVATARprevious commit author avatarhttps://git.example.com/avatars/12
Previous pipeline
CI_PREV_PIPELINE_NUMBERprevious pipeline number7
CI_PREV_PIPELINE_PARENTprevious pipeline number of parent pipeline0
CI_PREV_PIPELINE_EVENTprevious pipeline event (see event)push, pull_request, pull_request_closed, tag, release, manual, cron
CI_PREV_PIPELINE_URLprevious pipeline link in CIhttps://ci.example.com/repos/7/pipeline/7
CI_PREV_PIPELINE_FORGE_URLprevious pipeline link to event in forgehttps://git.example.com/john-doe/my-repo/commit/15784117e4e103f36cba75a9e29da48046eb82c4
CI_PREV_PIPELINE_DEPLOY_TARGETprevious pipeline deploy target for deployment eventsproduction
CI_PREV_PIPELINE_DEPLOY_TASKprevious pipeline deploy task for deployment eventsmigration
CI_PREV_PIPELINE_STATUSprevious pipeline statussuccess, failure
CI_PREV_PIPELINE_CREATEDprevious pipeline created UNIX timestamp1722610173
CI_PREV_PIPELINE_STARTEDprevious pipeline started UNIX timestamp1722610173
CI_PREV_PIPELINE_FINISHEDprevious pipeline finished UNIX timestamp1722610383
โ€ƒ
CI_WORKSPACEPath of the workspace where source code gets cloned to/woodpecker/src/git.example.com/john-doe/my-repo
System
CI_SYSTEM_NAMEname of the CI systemwoodpecker
CI_SYSTEM_URLlink to CI systemhttps://ci.example.com
CI_SYSTEM_HOSThostname of CI serverci.example.com
CI_SYSTEM_VERSIONversion of the server2.7.0
Forge
CI_FORGE_TYPEname of forgebitbucket , bitbucket_dc , forgejo , gitea , github , gitlab
CI_FORGE_URLroot URL of configured forgehttps://git.example.com
Internal - Please don't use!
CI_SCRIPTInternal script path. Used to call pipeline step commands.
CI_NETRC_USERNAMECredentials for private repos to be able to clone data. (Only available for specific images)
CI_NETRC_PASSWORDCredentials for private repos to be able to clone data. (Only available for specific images)
CI_NETRC_MACHINECredentials for private repos to be able to clone data. (Only available for specific images)

Global environment variablesโ€‹

If you want specific environment variables to be available in all of your pipelines use the WOODPECKER_ENVIRONMENT setting on the Woodpecker server. Note that these can't overwrite any existing, built-in variables.

WOODPECKER_ENVIRONMENT=first_var:value1,second_var:value2

These can be used, for example, to manage the image tag used by multiple projects.

WOODPECKER_ENVIRONMENT=GOLANG_VERSION:1.18
 steps:
- name: build
- image: golang:1.18
+ image: golang:${GOLANG_VERSION}
commands:
- [...]

String Substitutionโ€‹

Woodpecker provides the ability to substitute environment variables at runtime. This gives us the ability to use dynamic settings, commands and filters in our pipeline configuration.

Example commit substitution:

 steps:
- name: docker
image: woodpeckerci/plugin-kaniko
settings:
+ tags: ${CI_COMMIT_SHA}

Example tag substitution:

 steps:
- name: docker
image: woodpeckerci/plugin-kaniko
settings:
+ tags: ${CI_COMMIT_TAG}

String Operationsโ€‹

Woodpecker also emulates bash string operations. This gives us the ability to manipulate the strings prior to substitution. Example use cases might include substring and stripping prefix or suffix values.

OPERATIONDESCRIPTION
${param}parameter substitution
${param,}parameter substitution with lowercase first char
${param,,}parameter substitution with lowercase
${param^}parameter substitution with uppercase first char
${param^^}parameter substitution with uppercase
${param:pos}parameter substitution with substring
${param:pos:len}parameter substitution with substring and length
${param=default}parameter substitution with default
${param##prefix}parameter substitution with prefix removal
${param%%suffix}parameter substitution with suffix removal
${param/old/new}parameter substitution with find and replace

Example variable substitution with substring:

 steps:
- name: docker
image: woodpeckerci/plugin-kaniko
settings:
+ tags: ${CI_COMMIT_SHA:0:8}

Example variable substitution strips v prefix from v.1.0.0:

 steps:
- name: docker
image: woodpeckerci/plugin-kaniko
settings:
+ tags: ${CI_COMMIT_TAG##v}