If a native cube, while running, changes the worker environment, such as installs a package, creates or deletes a file, etc., such environment will still be there for all other cubes running within a single task.
Docker cube: Runs within a Docker container started on a worker. Technically, it runs a custom script or a container script, if the container has an entry point.
If a Docker cube, while running, changes the environment, such environment will be available to other cubes within the task only in case the changes were made within the /sourcecraft directory. All other changes will be removed along with the Docker container.
When working from a container, the directories are mounted as follows:
The directory housing files associated with the task in progress is mounted to /sourcecraft.
The directory to clone the repository to and that is also the working directory (workdir) by default, is mounted to /sourcecraft/workspace.
You can get the paths of these directories from the $SOURCECRAFT_ROOT_DIRECTORY and $SOURCECRAFT_WORKSPACEpredefined environment variables, respectively.
To configure a Docker cube, use the image property to specify the Docker image name and, optionally, username, password, entry point, and arguments.
In cubes, you can use environment variables and secrets. To provide environment variables from a certain cube to others as KEY=VALUE pairs, you can use the $SOURCECRAFT_ENVpredefined variable.
By default, cubes within a single task are run one by one. To link cubes, use the needs property, where you can specify the list of cubes to execute before the current one. If you skip this property, the cube will depend on the one defined immediately before it.
The artifacts that may be created after the cube is run are saved for further use. They will be available for download from the cube in the CI/CD section of the repository for 14 days.
Supported properties:
name: Cube name.
script: Command to execute in the cube.
needs: List of cubes to execute before the current one.
image: Docker image used to execute the cube. This is an optional property. For more information, see image.
artifacts: List of paths to the files that will be created after the cube is run and saved for further use. The artifacts will be available for download from the cube in the CI/CD section of the repository for 14 days.
Example of a cube configuration using variables, including predefined ones
workflows:my-workflow:tasks:-name:my-task# Here you define variables that will be shared among all cubesenv:TASK_ENV_VAR:Thisvariableisavailableinallcubesofthistask.# Multi-line variableMULTILINE_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 this cubeenv:CUBE_ENV_VAR:Thisvariableisavailableonlyincubemy-cube-1.# Variable with a value from a secretSECRET_VAR:${{secrets.<secret_name>}}script:-echo"$TASK_ENV_VAR"-echo"$MULTILINE_VAR"-echo"$CUBE_ENV_VAR"-echo"$SECRET_VAR"-name:my-cube-2# Here you define variables that will only be available within this cubeenv:CUBE_ENV_VAR:Thisvariableisavailableonlyincubemy-cube-2.script:-echo"$TASK_ENV_VAR"-echo"$CUBE_ENV_VAR"# Using a predefined variable-echo"$SOURCECRAFT_TASK"
Example of a Docker image configuration with authentication
If authentication is required to access the registry, you can use the docker login command in your task or configure authentication in the image section and use a secret, e.g.:
To run commands in the container context, specify the Docker image path in the registry using the image or image:name property, and provide the commands in the script property, e.g.:
If the container has a redefined entry point, you will need to reset the latter before running a command from script. You can do this by specifying "" in the entrypoint property. For example, you can use a container that has the ENTRYPOINT ["/usr/bin/docker"] entry point set by default:
Providing command-line arguments to a Docker container
To provide arguments, which you need to run a container, to a container with a redefined entry point, use the args property. For example, this may be the case for a container used to create a new Docker image: