---
metadata:
  - name: generator
    content: Diplodoc Platform v5.54.2
alternate:
  - https://sourcecraft.dev/portal/docs/en/sourcecraft/ci-cd-ref/env-vars-between-cubes.md
  - https://sourcecraft.dev/portal/docs/ru/sourcecraft/ci-cd-ref/env-vars-between-cubes.md
  - href: en/sourcecraft/ci-cd-ref/env-vars-between-cubes.md
    type: text/markdown
    title: Markdown version
  - href: ../../llms.txt
    type: text/markdown
    title: llms.txt
---
> **Documentation Index:** Fetch the complete configuration index at https://sourcecraft.dev/portal/docs/en/llms.txt

# Providing environment variables from one cube to another

In SourceCraft [CI/CD](https://sourcecraft.dev/portal/docs/en/sourcecraft/concepts/ci-cd.md), you can provide environment variables from one cube to another using special [predefined](https://sourcecraft.dev/portal/docs/en/sourcecraft/ci-cd-ref/predefined-variables.md) [SOURCECRAFT_ENV](#env) and [SOURCECRAFT_OUTPUT](#output) environment variables.


## SOURCECRAFT_ENV {#env}

The variable that provides environment variables from a certain cube to others as `KEY=VALUE` pairs. To write to the variable, the `>>` input redirect operator is used.

The values ​​written in `SOURCECRAFT_ENV` in one cube are provided to the next ones within the same task.


### Example of providing single-line values ​​to SOURCECRAFT_ENV {#env-single-line}

```yaml
on:
  push:
    - workflows: [ env-single-line ]

workflows:
  env-single-line:
    tasks:
      - name: env-single-line-task
        cubes:
          - name: input
            script:
              - echo "VER=1.0.1" >> $SOURCECRAFT_ENV  # Writing to a variable
              - echo "VAR1=SOME_VALUE" >> $SOURCECRAFT_ENV  # Writing to a variable
          - name: use-env
            script:
              - echo $VER  # Output of a variable
              - echo $VAR1  # Output of a variable
```


### Example of providing multi-line values ​​to SOURCECRAFT_ENV {#env-multi-line}

```yaml
on:
  push:
    - workflows: [ env-multi-line ]

workflows:
  env-multi-line:
    tasks:
      - name: env-multi-line-task
        cubes:
          - name: input
            script:  # Writing a multi-line value to a variable
              - |
                echo "my_var_multiline<<EOF
                line1
                line2
                EOF" >> $SOURCECRAFT_ENV
          - name: use-env
            script:
              - echo $my_var_multiline # Output of a variable
```


## SOURCECRAFT_OUTPUT {#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.

The values ​​written in `SOURCECRAFT_OUTPUT` in one cube become available to the next ones within the same task. To use the provided value, you need to access it in the next cube using this special syntax: `${{ cubes.<name_of_original_cube>.outputs.<key> }}`.


### Example of providing single-line values ​​to SOURCECRAFT_OUTPUT {#output-single-line}

```yaml
on:
  push:
    - workflows: [ output-single-line ]

workflows:
  output-single-line:
    tasks:
      - name: output-single-line-task
        cubes:
          - name: inputcube
            script:
              - echo "outputvar=my-value" >> $SOURCECRAFT_OUTPUT  # Writing to a variable
          - name: outputcube
            env:
              MY_ENV: "${{ cubes.inputcube.outputs.outputvar }}"  # Getting a value
```


### Example of providing multi-line values ​​to SOURCECRAFT_OUTPUT {#output-multi-line}

```yaml
on:
  push:
    - workflows: [ output-multi-line ]

workflows:
  output-multi-line:
    tasks:
      - name: output-multi-line-task
        cubes:
          - name: inputcube
            script:  # Writing a multi-line value to a variable
              - |
                echo "outputvar<<EOF
                line3
                line4
                EOF" >> $SOURCECRAFT_OUTPUT
          - name: outputcube
            env:
              MY_ENV: "${{ cubes.inputcube.outputs.outputvar }}"  # Getting a value
```