Learn how to use pipeline variables.
Built-in pipeline environment variables
Built-in system environment variables start with `EMAS_`. These variables are reserved by the EMAS system. Do not define any environment variables that start with `EMAS_`.
EMAS_PIPELINE_NAME: The name of the currently running pipeline.
EMAS_PIPELINE_INSTANCE_ID: The instance ID of the currently running pipeline.
EMAS_PIPELINE_JOB_ID: The ID of the current pipeline stage.
EMAS_PIPELINE_TIMESTAMP: The start time of the current pipeline run (10-digit UNIX timestamp).
EMAS_RUNNER_WORK_DIR: The working directory in the secure container.
EMAS_RUNNER_CODE_DIR: The code directory in the secure container.
EMAS_RUNNER_ARTIFACT_DIR: The artifact directory in the secure container.
EMAS_RUNNER_OUTPUTS_FILE: The path to the output file in the secure container.
APP_KEY: The application key.
Built-in environment variables in the build environment
Android
ANDROID_HOME
ANDROID_NDK_HOME
ANDROID_CMAKE_HOME
JAVA_HOME_8
JAVA_HOME_11
JAVA_HOME_17
JAVA_HOME
HarmonyOS
COMMANDLINE_TOOL_DIR
HDC_HOME
JAVA_HOME_17
JAVA_HOME
Runtime variables
During runtime, specific plugins generate output variables. These variables can be environment variables or normal variables, and you can reference them in subsequent steps.
Code clone
Variable name |
Variable type |
Value description |
EMAS_SHA |
Environment variable |
The latest commit ID of the cloned code. |
EMAS_BRANCH |
Environment variable |
The branch name of the cloned code. |
Replace application version
Variable name |
Variable type |
Value description |
VERSION_NAME |
Environment variable |
The version name, such as 1.0.0. |
VERSION_CODE |
Environment variable |
The version code. This corresponds to VersionCode for Android/HarmonyOS. |
Upload build artifact
This plugin generates variables for the paths of your build artifacts.
Variable name |
Variable type |
Value description |
Relative path of artifact 1 |
Normal variable |
The key stored in OSS. |
Relative path of artifact 2 |
Normal variable |
The key stored in OSS. |
What is an artifact's relative path?
For example, on Android, if the path of a build artifact relative to the code root directory is `app/build/outputs/apk/release/app-release.apk`, and you enter `app/build/outputs` as the collection path in the plugin, then the artifact's relative path is `apk/release/app-release.apk`.
Custom Bash
You can output custom environment variables and normal variables to reference in subsequent steps.
Output a custom environment variable
......
echo "::set-env name=EXAMPLE_KEY::hello emas"
......
Output a custom normal variable
......
echo "example_key=hello emas" >> $EMAS_RUNNER_OUTPUTS_FILE
......
How to use custom normal variables
For example, you can add a Bash plugin and set its step ID to `Bash_1`. In `Bash_1`, output a normal variable named `example_key`. Then, add another Bash plugin and set its step ID to `Bash_2`. In the script for `Bash_2`, add the following content:
echo ${{ steps.Bash_1.outputs['example_key'] }}
This prints the value of `example_key` in the `Bash_2` step.
Variable references
Different types of variables are referenced in different ways. You must use the correct reference method for each scenario.
Scenarios for using variables
1. Use as an input parameter in a pipeline
2. Use in a custom script
echo "building..."
echo "VERSION = $VERSION"
echo "VERSION_CODE = $VERSION_CODE"
chmod +x ./gradlew
./gradlew clean assembleRelease
3. Reference in a build tool
You can reference system variables in Gradle .
Scenarios for each variable type
Variable usage scenarios |
|||
Variable type |
Pipeline input parameter |
Custom script |
Build tool reference |
Built-in pipeline environment variable |
Supported. Example: ${{ env.EMAS_PIPELINE_JOB_ID }} |
Supported. Example: $EMAS_PIPELINE_JOB_ID |
Support |
Built-in build environment variable |
Not supported |
Supported. Example: $ANDROID_HOME |
Support |
Runtime environment variable |
Supported. Example: ${{ env.VERSION_CODE }} |
Supported. Example: $VERSION_CODE |
Supported |
Runtime normal variable |
Supported. Example: ${{ steps.Bash_1.outputs['example_key'] }} |
Not supported |
Not supported |
Cross-stage variable references
Not supported