---
metadata:
  - name: generator
    content: Diplodoc Platform v5.54.2
alternate:
  - https://sourcecraft.dev/portal/docs/en/sourcecraft/ci-cd-ref/env.md
  - https://sourcecraft.dev/portal/docs/ru/sourcecraft/ci-cd-ref/env.md
  - href: en/sourcecraft/ci-cd-ref/env.md
    type: text/markdown
    title: Markdown version
  - href: ../../llms.txt
    type: text/markdown
    title: llms.txt
title: Environment variables (env)
description: 'Description of environment variables in SourceCraft CI/CD processes: syntax, scopes, and use cases.'
---
> **Documentation Index:** Fetch the complete configuration index at https://sourcecraft.dev/portal/docs/en/llms.txt


# Environment variables (env)

<!-- 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 -->

`env` section structure:

```yaml
env:
  # Variable name and value.
  <name>: <value>
```

Example of using variables:

<!-- 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 -->

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

* [Managing secrets in a SourceCraft repository](https://sourcecraft.dev/portal/docs/en/sourcecraft/operations/secrets.md)
* [Configuring a service connection to Yandex Cloud in SourceCraft](https://sourcecraft.dev/portal/docs/en/sourcecraft/operations/service-connections.md)