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.

The Scope column documents when each variable can be used:

  • config: the variable is available at config-evaluation time, when the pipeline configuration is parsed. It can be referenced in when filters and expanded via string substitution (e.g. ${CI_COMMIT_SHA}).
  • runtime: the variable is available as an environment variable inside the running step.

Most variables are available in both scopes. Variables scoped only to runtime (e.g. the step-specific variables and CI_PIPELINE_STATUS) are not populated while the configuration is evaluated, so they cannot be used in when filters or substitutions.

NAMEScopeDescriptionExample
CIconfig, runtimeCI environment namewoodpecker
Repository
CI_REPOconfig, runtimerepository full name <owner>/<name>john-doe/my-repo
CI_REPO_OWNERconfig, runtimerepository ownerjohn-doe
CI_REPO_NAMEconfig, runtimerepository namemy-repo
CI_REPO_REMOTE_IDconfig, runtimerepository remote ID, is the UID it has in the forge82
CI_REPO_URLconfig, runtimerepository web URLhttps://git.example.com/john-doe/my-repo
CI_REPO_CLONE_URLconfig, runtimerepository clone URLhttps://git.example.com/john-doe/my-repo.git
CI_REPO_CLONE_SSH_URLconfig, runtimerepository SSH clone URLgit@git.example.com:john-doe/my-repo.git
CI_REPO_DEFAULT_BRANCHconfig, runtimerepository default branchmain
CI_REPO_PRIVATEconfig, runtimerepository is privatetrue
CI_REPO_TRUSTED_NETWORKconfig, runtimerepository has trusted network accessfalse
CI_REPO_TRUSTED_VOLUMESconfig, runtimerepository has trusted volumes accessfalse
CI_REPO_TRUSTED_SECURITYconfig, runtimerepository has trusted security accessfalse
Current Commit
CI_COMMIT_SHAconfig, runtimecommit SHAdeadbee...
CI_COMMIT_REFconfig, runtimecommit refrefs/heads/main
CI_COMMIT_REFSPECconfig, runtimecommit ref specissue-branch:main
CI_COMMIT_BRANCHconfig, runtimecommit branch (equals target branch for pull requests)main
CI_COMMIT_SOURCE_BRANCHconfig, runtimecommit source branch (set only for pull request events)issue-branch
CI_COMMIT_TARGET_BRANCHconfig, runtimecommit target branch (set only for pull request events)main
CI_COMMIT_TAGconfig, runtimecommit tag name (empty if event is not tag)v1.10.3
CI_COMMIT_PULL_REQUESTconfig, runtimecommit pull request number (set only for pull request events)1
CI_COMMIT_PULL_REQUEST_LABELSconfig, runtimelabels assigned to pull request (set only for pull request events)server
CI_COMMIT_PULL_REQUEST_MILESTONEconfig, runtimemilestone assigned to pull request (set only for pull_request and pull_request_closed events)summer-sprint
CI_COMMIT_PULL_REQUEST_DRAFTconfig, runtimewhether the pull request is a draft (set only for pull request events; see forge support)true, false
CI_COMMIT_MESSAGEconfig, runtimecommit messageInitial commit
CI_COMMIT_TIMESTAMPconfig, runtimecommit UNIX timestamp1722617519
CI_COMMIT_AUTHORconfig, runtimecommit author usernamejohn-doe
CI_COMMIT_AUTHOR_EMAILconfig, runtimecommit author email addressjohn-doe@example.com
CI_COMMIT_PRERELEASEconfig, runtimerelease is a pre-release (empty if event is not release) — deprecated, use CI_PIPELINE_RELEASE_PREfalse
Current pipeline
CI_PIPELINE_NUMBERconfig, runtimepipeline number8
CI_PIPELINE_PARENTconfig, runtimenumber of parent pipeline0
CI_PIPELINE_STATUSruntimestate of the workflow right before the step was startedsuccess, failure
CI_PIPELINE_EVENTconfig, runtimepipeline event (see event)push
pull_request
pull_request_closed
pull_request_metadata
tag
release
manual
cron
CI_PIPELINE_EVENT_REASONconfig, runtimeexact reason why pull_request_metadata event was send. it is forge instance specific and can changelabel_updated
milestoned
demilestoned
assigned
edited
...
CI_PIPELINE_URLconfig, runtimelink to the web UI for the pipelinehttps://ci.example.com/repos/7/pipeline/8
CI_PIPELINE_FORGE_URLconfig, runtimelink to the forge's web UI for the commit(s) or tag that triggered the pipelinehttps://git.example.com/john-doe/my-repo/commit/deadbee...
CI_PIPELINE_DEPLOY_TARGETconfig, runtimepipeline deploy target for deployment eventsproduction
CI_PIPELINE_DEPLOY_TASKconfig, runtimepipeline deploy task for deployment eventsmigration
CI_PIPELINE_RELEASE_TITLEconfig, runtimerelease title (empty if event is not release)v1.10.3
CI_PIPELINE_RELEASE_PREconfig, runtimerelease is a pre-release (empty if event is not release)false
CI_PIPELINE_CREATEDconfig, runtimepipeline created UNIX timestamp1722617519
CI_PIPELINE_STARTEDconfig, runtimepipeline started UNIX timestamp1722617519
CI_PIPELINE_FILESconfig, runtimechanged files (empty if event is not push or pull_request), it is undefined if more than 500 files are touched[], [".woodpecker.yml","README.md"]
CI_PIPELINE_AUTHORconfig, runtimepipeline author usernameoctocat
CI_PIPELINE_AVATARconfig, runtimepipeline author avatarhttps://git.example.com/avatars/5dcbcadbce6f87f8abef
CI_PIPELINE_RERUNSconfig, runtimenumber of times the pipeline has been restarted; not set on the initial run, 1 after the first restart, incremented on each subsequent restart1
Current workflow
CI_WORKFLOW_NAMEconfig, runtimeworkflow namerelease
Current step
CI_STEP_NAMEruntimestep namebuild package
CI_STEP_TYPEruntimestep type (commands, plugin, service, clone or cache)commands
CI_STEP_NUMBERruntimestep number0
CI_STEP_STARTEDruntimestep started UNIX timestamp1722617519
CI_STEP_URLruntimeURL to step in UIhttps://ci.example.com/repos/7/pipeline/8
Previous commit
CI_PREV_COMMIT_SHAconfig, runtimeprevious commit SHAdeadbee...
CI_PREV_COMMIT_REFconfig, runtimeprevious commit refrefs/heads/main
CI_PREV_COMMIT_REFSPECconfig, runtimeprevious commit ref specissue-branch:main
CI_PREV_COMMIT_BRANCHconfig, runtimeprevious commit branchmain
CI_PREV_COMMIT_SOURCE_BRANCHconfig, runtimeprevious commit source branch (set only for pull request events)issue-branch
CI_PREV_COMMIT_TARGET_BRANCHconfig, runtimeprevious commit target branch (set only for pull request events)main
CI_PREV_COMMIT_URLconfig, runtimeprevious commit link in forgehttps://git.example.com/john-doe/my-repo/commit/deadbee...
CI_PREV_COMMIT_MESSAGEconfig, runtimeprevious commit messagetest
CI_PREV_COMMIT_TIMESTAMPconfig, runtimeprevious commit UNIX timestamp1722617519
CI_PREV_COMMIT_AUTHORconfig, runtimeprevious commit author usernamejohn-doe
CI_PREV_COMMIT_AUTHOR_EMAILconfig, runtimeprevious commit author email addressjohn-doe@example.com
Previous pipeline
CI_PREV_PIPELINE_NUMBERconfig, runtimeprevious pipeline number7
CI_PREV_PIPELINE_PARENTconfig, runtimeprevious pipeline number of parent pipeline0
CI_PREV_PIPELINE_EVENTconfig, runtimeprevious pipeline event (see event)push
pull_request
pull_request_closed
pull_request_metadata
tag
release
manual
cron
CI_PREV_PIPELINE_EVENT_REASONconfig, runtimeprevious exact reason pull_request_metadata event was send. it is forge instance specific and can changelabel_updated
milestoned
demilestoned
assigned
edited
...
CI_PREV_PIPELINE_URLconfig, runtimeprevious pipeline link in CIhttps://ci.example.com/repos/7/pipeline/7
CI_PREV_PIPELINE_FORGE_URLconfig, runtimeprevious pipeline link to event in forgehttps://git.example.com/john-doe/my-repo/commit/deadbee...
CI_PREV_PIPELINE_DEPLOY_TARGETconfig, runtimeprevious pipeline deploy target for deployment eventsproduction
CI_PREV_PIPELINE_DEPLOY_TASKconfig, runtimeprevious pipeline deploy task for deployment eventsmigration
CI_PREV_PIPELINE_STATUSconfig, runtimeprevious pipeline statussuccess, failure
CI_PREV_PIPELINE_CREATEDconfig, runtimeprevious pipeline created UNIX timestamp1722610173
CI_PREV_PIPELINE_STARTEDconfig, runtimeprevious pipeline started UNIX timestamp1722610173
CI_PREV_PIPELINE_FINISHEDconfig, runtimeprevious pipeline finished UNIX timestamp1722610383
CI_PREV_PIPELINE_AUTHORconfig, runtimeprevious pipeline author usernameoctocat
CI_PREV_PIPELINE_AVATARconfig, runtimeprevious pipeline author avatarhttps://git.example.com/avatars/5dcbcadbce6f87f8abef
CI_WORKSPACEruntimePath of the workspace where source code gets cloned to/woodpecker/src/git.example.com/john-doe/my-repo
System
CI_SYSTEM_NAMEconfig, runtimename of the CI systemwoodpecker
CI_SYSTEM_URLconfig, runtimelink to CI systemhttps://ci.example.com
CI_SYSTEM_HOSTconfig, runtimehostname of CI serverci.example.com
CI_SYSTEM_VERSIONconfig, runtimeversion of the server2.7.0
Forge
CI_FORGE_TYPEconfig, runtimename of forgebitbucket
bitbucket_dc
forgejo
gitea
github
gitlab
CI_FORGE_URLconfig, runtimeroot URL of configured forgehttps://git.example.com
Internal - Please don't use!
CI_SCRIPTruntimeInternal script path. Used to call pipeline step commands.
CI_NETRC_USERNAMEruntimeCredentials for private repos to be able to clone data. (Only available for specific images)
CI_NETRC_PASSWORDruntimeCredentials for private repos to be able to clone data. (Only available for specific images)
CI_NETRC_MACHINEruntimeCredentials 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: s3
image: woodpeckerci/plugin-s3
settings:
+ target: /target/${CI_COMMIT_SHA}

Example tag substitution:

steps:
- name: s3
image: woodpeckerci/plugin-s3
settings:
+ target: /target/${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: s3
image: woodpeckerci/plugin-s3
settings:
+ target: /target/${CI_COMMIT_SHA:0:8}

Example variable substitution strips v prefix from v.1.0.0:

steps:
- name: s3
image: woodpeckerci/plugin-s3
settings:
+ target: /target/${CI_COMMIT_TAG##v}

CI_COMMIT_PULL_REQUEST_DRAFT forge support

For pull request events, CI_COMMIT_PULL_REQUEST_DRAFT is set to true or false depending on whether the pull request is a draft.

ForgeSupportedNotes
GitHub
Gitea
GitLabUses draft; falls back to legacy work_in_progress when needed
ForgejoWebhook payloads include draft status, but it is not exposed yet
BitbucketWebhook payloads include draft status, but it is not exposed yet
Bitbucket DatacenterWebhook payloads include draft status, but it is not exposed yet

On unsupported forges the variable is still set to false.

pull_request_metadata specific event reason values

For the pull_request_metadata event, the exact reason a metadata change was detected is passe through in CI_PIPELINE_EVENT_REASON.

GitLab merges metadata updates into one webhook. Event reasons are separated by , as a list.

note

Event reason values are forge-specific and may change between versions.

EventGitHubGiteaForgejoGitLabBitbucketBitbucket DatacenterDescription
assignedPull request was assigned to a user
converted_to_draftPull request was converted to a draft
demilestonedPull request was removed from a milestone
description_editedDescription edited
editedThe title or body of a pull request was edited, or the base branch was changed
label_addedPull had no labels and now got label(s) added
label_clearedAll labels removed
label_updatedNew label(s) added / label(s) changed
lockedConversation on a pull request was locked
milestonedPull request was added to a milestone
ready_for_reviewDraft pull request was marked as ready for review
review_requestedNew review was requested
title_editedTitle edited
unassignedUser was unassigned from a pull request
unlabeledLabel was removed from a pull request
unlockedConversation on a pull request was unlocked

Bitbucket and Bitbucket Datacenter are not supported at the moment.