Providing environment variables from one cube to another

In SourceCraft CI/CD, you can provide environment variables from one cube to another using special predefined SOURCECRAFT_ENV and SOURCECRAFT_OUTPUT environment variables.

SOURCECRAFT_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

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

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

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

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

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