Updated on 2024-12-16 GMT+08:00

Pipeline Contexts

Contexts are a way to access information about pipeline runs, sources, variables, and jobs. Each context is an object that contains various attributes. The following table lists pipeline contexts.

Table 1 Pipeline contexts

Context

Type

Description

pipeline

object

Information about the pipeline run.

sources

object

Information about the pipeline sources in each pipeline run.

env

object

Information about the custom parameters in each pipeline run.

jobs

object

Information about jobs that have reached the final states in each pipeline run.

Context Reference Format

${{ <context>.<attribute_name> }}

context indicates the pipeline context, attribute_name indicates the attribute.

Contexts Attributes

Table 2 Context attributes

Context

Attribute

Type

Description

Example

pipeline context

pipeline

object

Information about the pipeline run. This object contains the following attributes: project_id, pipeline_id, run_number, timestamp, trigger_type, and run_id.

  • Content example

    The following example shows the pipeline context information contained in a manually executed pipeline.

    {
        "project_id": "6428c2e2b4b64affa14ec80896695c49",
        "pipeline_id": "f9981060660249a3856f46c2c402f244",
        "run_number": "168",
        "timestamp": "20231016000004",
        "trigger_type": "Manual",
        "run_id": "c2f507f93510459190b543e47f6c9bec"
    }
  • Usage example

    To obtain the triggering mode of the current pipeline, you can use the following syntax:

    ${{ pipeline.trigger_type }}

pipeline.project_id

string

ID of the project to which the current pipeline belongs. This string is the same as the predefined parameter PROJECT_ID.

pipeline.pipeline_id

string

Current pipeline ID. This string is the same as the predefined parameter PIPELINE_ID.

pipeline.run_number

string

Pipeline execution number. This string is the same as the predefined parameter PIPELINE_NUMBER.

pipeline.timestamp

string

Pipeline execution timestamp. This string is the same as the predefined parameter TIMESTAMP. The format is yyyyMMddHHmmss. For example, 20211222124301.

pipeline.trigger_type

string

Pipeline triggering type. This string is the same as the predefined parameter PIPELINE_TRIGGER_TYPE.

pipeline.run_id

string

Pipeline execution ID. This string is the same as the predefined parameter PIPELINE_RUN_ID.

sources context

sources

object

Information about the pipeline sources in each pipeline run. This object contains the following attributes: alias, repo_name, commit_id, commit_id_short, commit_message, repo_url, repo_type, repo_name, ssh_repo_url, tag, merge_id, source_branch, and target_branch.

  • Content example

    The following example shows the sources context information contained in a manually executed pipeline with a single code source. The alias of pipeline source is my_repo.

    {
        "my_repo": {
            "commit_id": "dedb73bb9abfdaab7d810f2616bae9d2b6632ecc",
            "commit_id_short": "dedb73bb",
            "commit_message": "maven0529 update pipeline0615.yml",
            "repo_url": "https://example.com/clsyz00001/maven0529.git",
            "repo_type": "codehub",
            "repo_name": "maven0529",
            "ssh_repo_url": "git@example.com:clsyz00001/maven0529.git",
            "target_branch": "master"
        }
    }
  • Usage example

    To obtain the running branch of the pipeline, you can use the following syntax:

    ${{ sources.my_repo.target_branch }}

sources.<alias>

object

Information about the pipeline source which has an alias.

sources.<repo_name>

object

Information about the pipeline source which does not have an alias but only a repository name. It contains the same information as that in sources.<alias>.

sources.<alias>.commit_id

string

The last commit ID before execution. This string is the same as the predefined parameter COMMIT_ID.

sources.<alias>.commit_id_short

string

The first 8 characters of the last commit ID before execution. This string is the same as the predefined parameter COMMIT_ID_SHORT.

sources.<alias>.commit_message

string

The commit information from the last code commit before the pipeline execution.

sources.<alias>.repo_url

string

Code repository address (HTTPS). This string is the same as the predefined parameter REPO_URL.

sources.<alias>.repo_type

string

Type of the code repository. For example, codehub, gitlab, github, gitee, and general_git.

sources.<alias>.repo_name

string

Name of the code repository.

sources.<alias>.ssh_repo_url

string

Code repository address (SSH).

sources.<alias>.tag

string

Tag name when the tag is triggered.

sources.<alias>.merge_id

string

Merge request ID when the merge request is triggered.

sources.<alias>.source_branch

string

Source branch name when the merge request is triggered.

sources.<alias>.target_branch

string

If the merge request is triggered, this string indicates the name of the target branch. Otherwise, this string indicates the name of the running branch.

env context

name

string

Name of a custom parameter.

  • Content example

    The following example shows the env context information in a run, which includes two custom parameters.

    {
        "var_1": "val1",
        "var_2": "val2"
    }
  • Usage example

    To obtain the value of the custom parameter var_1, you can use the following syntax:

    ${{ env.var_1 }}

value

string

Value of a custom parameter.

jobs context

jobs

object

Information about jobs in a pipeline. This object contains the following attributes: job_id, status, outputs, output_name, metrics, and metric_name.

  • Content example

    The following example shows the jobs context information in a run. There are two successfully executed jobs. The output of the check_job job is two metrics, and the output of the demo_job job is two general outputs.

    {
        "check_job": {
            "status": "COMPLETED",
            "metrics": {
                "critical": "0",
                "major": "0"
            }
        },
        "demo_job": {
            "status": "COMPLETED",
            "outputs": {
                "output1": "val1",
                "output2": "val2"
            }
        }
    }
  • Usage example

    To obtain the value of output1 of demo_job, you can use the following syntax:

    ${{ jobs.demo_job.outputs.output1 }}

jobs.<job_id>

object

Information about the job with a specified ID.

jobs.<job_id>.status

string

Job execution result. The value can be INIT, QUEUED, RUNNING, CANCELED, COMPLETED, FAILED, PAUSED, IGNORED, SUSPEND, or UNSELECTED.

jobs.<job_id>.outputs

object

The running value, as a key-value pair.

jobs.<job_id>.outputs.<output_name>

string

The running value name.

jobs.<job_id>.metrics

object

The running metrics of a job. For example, the number of code check issues and the test pass rate.

jobs.<job_id>.metrics.<metric_name>

string

The running metric name of a job.