Predefined environment variables

SourceCraft automatically sets values for some environment variables. You can use them in your CI/CD workflows.

Variable

Description

CI

Means that the task is running in a CI environment, which is always true.

SOURCECRAFT_BASE_REF

Name of the pull request target branch (the branch you plan to edit), e.g., main or team/integration. Provided only when starting and restarting pull request checks.

SOURCECRAFT_BASE_SHA

SHA hash of the commit for which the list of changes is calculated. The values it takes depend on the event that prompted the workflow execution:

  • SHA hash of the previous branch commit if pushing changes to a remote repository branch (on.push).
  • SHA hash of the last target branch commit (merge-base) if creating a pull request (on.pull_request).
  • Empty value if starting the CI/CD workflow manually (manual).

SOURCECRAFT_CHECKOUT_ENABLED

Indicates whether or not to clone the repository automatically. It equals the checkout:enabled value. The default value is true.

SOURCECRAFT_CI

Means that the task is running in a SourceCraft CI/CD environment, which is always true.

SOURCECRAFT_COMMIT_AUTHOR

Commit author, in Name email format.

SOURCECRAFT_COMMIT_DESCRIPTION

Commit description. If the title is less than 100 characters, the message is displayed without a title; otherwise, the entire message is displayed.

SOURCECRAFT_COMMIT_MESSAGE

Commit message.

SOURCECRAFT_COMMIT_REF

Full name of the branch or tag (fully-formed ref name) that caused the workflow execution, e.g., refs/heads/main or refs/tags/v1.1.

SOURCECRAFT_COMMIT_REF_NAME

Name of the branch or tag (short ref name) that caused the workflow execution, e.g., main or v1.1.

SOURCECRAFT_COMMIT_SHA

SHA hash of the commit after which the workflow started.

SOURCECRAFT_COMMIT_SHORT_SHA

First 8 characters of SOURCECRAFT_COMMIT_SHA

SOURCECRAFT_COMMIT_TIMESTAMP

Commit timestamp in ISO 8601 format, e.g., 2025-03-03T23:41:19Z. The UTC zone is used by default.

SOURCECRAFT_COMMIT_TITLE

Commit title, i.e., the first line of the message.

SOURCECRAFT_COMMITTER

Committer who added the commit to the target branch, in Name email format.

SOURCECRAFT_CUBE

Name of the cube in progress.

SOURCECRAFT_CUBE_ARTIFACTS

List of paths to cube artifacts relative to SOURCECRAFT_WORKSPACE, separated with ;. It is only defined for cubes with the specified artifacts.

SOURCECRAFT_CUBE_IMAGE

Docker image used by the cube. It is only defined for cubes which use a container.

SOURCECRAFT_ENV

The variable that provides environment variables from a certain cube to others as KEY=VALUE pairs. To write to such a variable, one uses >> (input redirect operator). For example:

cubes:
  - name: example
    script:
      - echo "VER=1.0.1" >> $SOURCECRAFT_ENV
      - echo "VAR1=SOME_VALUE" >> $SOURCECRAFT_ENV

All cubes to execute after example will have the provided values in VER and VAR1 variables.

SOURCECRAFT_EVENT

Type of the trigger event that prompted the workflow execution:

  • push: Pushing changes to a remote repository branch.
  • pull_request: Creating a pull request.
  • restart: Restarting the CI/CD workflow.
  • manual: Starting the CI/CD workflow manually.

SOURCECRAFT_OUTPUT

Variable that provides KEY=VALUE pairs from one cube to another via the outputs section. To write to the variable, the >> input redirect operator is used. For example:

on:
  pull_request:
    - workflows: output-test

workflows:
  output-test:
    tasks:
      - output-task

tasks:
  - name: output-task
    cubes:
      - name: env-input-cube
        script:
          - echo "my-name=my-value" >> $SOURCECRAFT_OUTPUT

      - name: env-output-cube
        env:
          # Insert the name of the cube with the variable, e.g., 
          # env-input-cube, to the outputs section.
          MY_ENV: "${{ cubes.<name_of_cube_with_variable>.outputs.my-name }}"
        script:
          - echo $MY_ENV

SOURCECRAFT_PR_ID

Unique ID (UUID) of the pull request within which the task was started.

SOURCECRAFT_PR_SLUG

Sequence number of the pull request within which the task was started, displayed in the SourceCraft interface.

SOURCECRAFT_REPO_ID

Unique ID (UUID) of the repository in which the current task is running.

SOURCECRAFT_ROOT_DIRECTORY

Path to the directory housing files associated with the task in progress.

SOURCECRAFT_RUN_ID

Custom SourceCraft CI/CD execution number, monotonously increasing. You can use it for versioning.

SOURCECRAFT_TASK

Name of the task in progress.

SOURCECRAFT_TASK_DATA

Path to the directory housing auxiliary files of the task in progress.

SOURCECRAFT_TOKEN

Token for authenticating in the SourceCraft API from within the CI/CD workflow. Example of getting a list of user issues:

on:
  push: test-workflow
workflows:
  test-workflow:
    tasks:
      - name: issues-task
        cubes:
          - name: i-have-got-issues
            script:
              - |
                curl -H "Authorization: Bearer $SOURCECRAFT_TOKEN" "https://api.sourcecraft.tech/me/issues" | jq

SOURCECRAFT_WORKFLOW

Name of the workflow in progress.

SOURCECRAFT_WORKSPACE

Path to the directory to clone the repository to. This directory is also the default directory (workdir) for cubes with a container.

See also