---
metadata:
  - name: generator
    content: Diplodoc Platform v5.54.2
alternate:
  - https://sourcecraft.dev/portal/docs/en/sourcecraft/operations/variables.md
  - https://sourcecraft.dev/portal/docs/ru/sourcecraft/operations/variables.md
  - href: en/sourcecraft/operations/variables.md
    type: text/markdown
    title: Markdown version
  - href: ../../llms.txt
    type: text/markdown
    title: llms.txt
title: Processing environment variables in SourceCraft
description: A guide on using environment variables in SourceCraft CI/CD processes to configure tasks and cubes.
---
> **Documentation Index:** Fetch the complete configuration index at https://sourcecraft.dev/portal/docs/en/llms.txt


# Processing environment variables in SourceCraft

<!-- source: en/_includes/sourcecraft/configuration-tip.md -->
{% note tip %}

You can set up and view repository configurations in the SourceCraft interface under ![image](../../_assets/console-icons/gear.svg) **Repository settings** in the ![image](../../_assets/console-icons/nut-hex.svg) **Configurations** section. Learn more in [this article](https://sourcecraft.dev/portal/docs/en/sourcecraft/operations/configuration-edit.md).

{% endnote %}
<!-- endsource: en/_includes/sourcecraft/configuration-tip.md -->

<!-- source: en/_includes/sourcecraft/ci-cd/ci-variables-description.md -->
The SourceCraft CI/CD processes support environment variables. The following variable scopes are available:
* Global: To provide the variables to all cubes of all tasks in all workflows.
* [Workflow](https://sourcecraft.dev/portal/docs/en/sourcecraft/concepts/ci-cd.md#workflows): To provide the variables to all cubes of all tasks of a specific workflow.
* [Task](https://sourcecraft.dev/portal/docs/en/sourcecraft/concepts/ci-cd.md#tasks): To provide the variables to all cubes linked to the task.
* [Cube](https://sourcecraft.dev/portal/docs/en/sourcecraft/concepts/ci-cd.md#cubes): To provide the variables to the specified cube.

You can reuse variables in nested scopes.

Also, you can use [predefined environment variables](https://sourcecraft.dev/portal/docs/en/sourcecraft/ci-cd-ref/predefined-variables.md).

{% note warning %}

Do not store any sensitive data, such as passwords, access keys, or tokens, in environment variables; use [secrets](https://sourcecraft.dev/portal/docs/en/sourcecraft/concepts/index.md#secrets) instead.

{% endnote %}
<!-- endsource: en/_includes/sourcecraft/ci-cd/ci-variables-description.md -->

To use environment variables in CI/CD processes:

1. [Configure](https://sourcecraft.dev/portal/docs/en/sourcecraft/operations/ci-cd.md) CI/CD in your repository.
1. In the `.sourcecraft/ci.yaml` configuration file, add the environment variables to the `tasks` or `cubes` section. Here is an example:

    <!-- source: en/_includes/sourcecraft/ci-cd/config-with-vars.md -->
    ```yaml
    # Defining global variables
    # to provide to all cubes of all tasks in all workflows.
    env:
      GLOBAL_VAR: global_var
      GLOBAL_SECRET: ${{ secrets.<secret_name> }}

    workflows:
      my-workflow:
        # Here you define variables that will be available in all cubes 
        # of all my-workflow tasks
        env:
          WORKFLOW_VAR: workflow-var
        
        tasks:
          - name: my-task
            # Here you define variables that will be available in all cubes 
            # within my-task
            env:
              TASK_ENV_VAR: This variable is available in all cubes of this task.
              # Multi-line variable
              MULTILINE_VAR: |
                multi-var
                multi-var
                this is my multi-var
            
            cubes:
              - name: my-cube-1
                # Here you define variables that will only be available
                # within my-cube-1
                env:
                  CUBE_ENV_VAR: This variable is available only in cube my-cube-1.
                  # Variable with a value from a secret
                  SECRET_VAR: ${{ secrets.<secret_name> }}
                  # Reusing global variables, 
                  # e.g., GLOBAL_VAR and GLOBAL_SECRET
                  LOCAL_VAR: ${{ env.<global_variable_1> }}
                  LOCAL_SECRET: ${{ env.<global_variable_2> }}
                  # Reusing workflow variables,
                  # e.g., WORKFLOW_VAR
                  LOCAL_VAR2: ${{ env.<workflow_variable> }}

                script:
                  - echo "$TASK_ENV_VAR"
                  - echo "$MULTILINE_VAR"
                  - echo "$CUBE_ENV_VAR"
                  - echo "$SECRET_VAR"
                  - echo "$WORKFLOW_VAR"
                  - echo "$LOCAL_VAR"
                  - echo "$LOCAL_VAR2"
                  - echo "$LOCAL_SECRET"

              - name: my-cube-2
                # Here you define variables that will only be available 
                # within my-cube-2
                env:
                  CUBE_ENV_VAR: This variable is available only in cube my-cube-2.
                script:
                  - echo "$TASK_ENV_VAR"
                  - echo "$CUBE_ENV_VAR"
                  # Using a predefined variable
                  - echo "$SOURCECRAFT_TASK"
                  - echo "$WORKFLOW_VAR"
                  - echo "$GLOBAL_VAR"

          - name: my-task-2
            cubes:
              - name: my-cube-3
                script:
                  - echo "$WORKFLOW_VAR"
                  - echo "$GLOBAL_VAR"
    ```
    <!-- endsource: en/_includes/sourcecraft/ci-cd/config-with-vars.md -->

1. Push changes to a remote repository.
1. [Check](https://sourcecraft.dev/portal/docs/en/sourcecraft/operations/ci-cd.md#check-ci-cd) the CI/CD process.

#### Useful links {#see-also}

* [Continuous integration and continuous deployment in SourceCraft](https://sourcecraft.dev/portal/docs/en/sourcecraft/concepts/ci-cd.md)
* [Configuring CI/CD in a SourceCraft repository](https://sourcecraft.dev/portal/docs/en/sourcecraft/operations/ci-cd.md)
* [Managing secrets in a SourceCraft repository](https://sourcecraft.dev/portal/docs/en/sourcecraft/operations/secrets.md)
* [CI/CD reference](https://sourcecraft.dev/portal/docs/en/sourcecraft/ci-cd-ref/index.md)
