Environment Variables

Create, map and use environment variables in tasks

When a task starts as part of your pipeline Sail CI mounts a set of default environment variables for every task:

CI
Set to "true" so that tools and tasks can behave differently in the context of continuous integration.

SAIL_CLONE_DIR
Absolute path of the repository cloned.

SAIL_COMMIT_REF
Full git ref for the cloned repository, you can read more at https://git-scm.com/book/en/v2/Git-Internals-Git-References.

SAIL_COMMIT_BRANCH
Branch for the commit cloned taken from the GIT_REF, for example, a git ref of "refs/heads/master" sets SAIL_COMMIT_BRANCH as "master".

SAIL_REPO_OWNER
Organisation or username for a repository, for example, https://github.com/sailci/demo sets SAIL_REPO_OWNER to "sailci".

SAIL_REPO_NAME
Name for a repository, for example, https://github.com/sailci/demo sets SAIL_REPO_NAME to "demo".

SAIL_COMMIT_SHA
Full SHA of the commit cloned an example would look similar to "70460b4b4aece5915caf5c68d12f560a9fe3e4".

SAIL_COMMIT_SHORT_SHA
Short SHA of the commit cloned consisting of the first seven characters, in the example above SAIL_COMMIT_SHORT_SHA is set to "70460b4".

SAIL_PULL_REQUEST_NUMBER
Number of pull request being built.

SAIL_PULL_REQUEST_REPO_OWNER
Pull request repositories owner, for example, https://github.com/sailci/demo sets SAIL_PULL_REQUEST_REPO_OWNER to "sailci".

SAIL_PULL_REQUEST_TITLE
Title for the pull request being built.

SAIL_PULL_REQUEST_URL
Full url that links to the pull request being built.

SAILCI
Helps determine a context for the environment a task runs. Useful for tasks requiring different behaviour based on the CI running it. Always set to "true".

Adding Custom Environment Variables

To add environment variables you need to use the Sail CI web application at https://app.sail.ci/

Use Environment Variables in Task Properties

To use environment variables within any part of your task properties such as "image", "command", "args" and "env" wrap the environment variable you wish to use with $(), for example, $(GIT_SHA).

Mapping Environment Variables

Sail CI provides incredible flexibility to map and use environment variables for a pipeline task. We have broken down how you can use them:


Hardcoded Environment Variables Values

For any given task you can map using a key and hardcoded value. Sail CI mounts these as specified into the task.

Example:

tasks:
  my-task:
    image: "sailci/example"
    env:
      - CUSTOM_ENV_VAR: "Hardcoded Value"

Custom Environment Variables

For any created environment variable (see "Adding New Environment Variables") you can specify keys and provide no value, Sail CI mounts them into the task automatically.

Example:

tasks:
  my-task:
    image: "sailci/example"
    env:
      - CUSTOM_ENV_VAR

Re-Mapping Environment Variables

You can map custom environment variables to a different name using the interpolation syntax (see Use Environment Variables in Task Properties). Set the value of the env variable using $(CUSTOM_VAR) syntax.

tasks:
  my-task:
    image: "sailci/example"
    env:
      - CUSTOM_ENV_VAR: $(OTHER_CUSTOM_VAR)
      - CUSTOM_GIT_SHA_VAR: $(GIT_SHA)

Note:

Builds for forked repositories that raise pull requests will not allow any custom environment variables to be attached to a task. Hardcoded values and re-mapping of Sail CI default environment variables are still available.