Environment Variables

Overview

This document describes the environment variables used in Semaphore 2.0 projects.

Although some of the presented environment variables are defined on a per project or on a per task basis, all the presented environment variables can be seen on a per job basis.

Predefined environment variables

Semaphore defines and uses its own environment variables.

This group of environment variables includes the environment variables that are related to Semaphore 2.0 and hold information that is specific to Semaphore 2.0.

CI

The value of the CI environment variable specifies whether we are in a Continuous Integration environment or not. The type of the CI variable is boolean.

Example value: true

SEMAPHORE

The value of the SEMAPHORE environment variable says whether the job is executed in the Semaphore 2.0 environment or not and is a boolean variable.

Example value: true

SEMAPHORE_PROJECT_NAME

The value of the SEMAPHORE_PROJECT_NAME environment variable holds the name of the project a job belongs to.

Example value: Documentation Project

SEMAPHORE_PROJECT_ID

The value of the SEMAPHORE_PROJECT_ID environment variable holds the project ID of the project that a job belongs to.

Example value: 0dd982e8-32f5-4037-983e-4de01ac7fb1e

SEMAPHORE_JOB_NAME

The value of the SEMAPHORE_JOB_NAME environment variable is a string that holds the name of the job.

Example value: Push image to Docker

SEMAPHORE_JOB_ID

The SEMAPHORE_JOB_ID environment variable holds the Job ID of the job that is being executed. It is the same value as is displayed in the output of the sem get jobs or the sem get jobs --all commands and is assigned by Semaphore 2.0.

Example value: a26d42cf-89ac-4c3f-9e2d-51bb231897bf

SEMAPHORE_JOB_RESULT

The value of the SEMAPHORE_JOB_RESULT environment variable holds the result of a job. The list of values includes none, passed, failed and stopped.

Example value: passed

SEMAPHORE_WORKFLOW_ID

The value of the SEMAPHORE_WORKFLOW_ID environment variable is the workflow ID that is used during the execution of the active job.

The SEMAPHORE_WORKFLOW_ID environment variable remains the same during a pipeline run and is available in all the blocks of a pipeline as well as in all promoted and auto promoted pipelines.

Example value: 65c9bb1c-aeb6-41f0-b8d9-6fa177241cdf

SEMAPHORE_PIPELINE_ID

The value of the SEMAPHORE_PIPELINE_ID environment variable is the pipeline ID that is used for the execution of the active job.

The SEMAPHORE_PIPELINE_ID environment variable remains the same throughout all the blocks of a pipeline, which makes it the perfect candidate for sharing data inside the same pipeline.

Example value: ea3e6bba-d19a-45d7-86a0-e78a2301b616

This group of environment variables includes environment variables that are used by Semaphore 2.0 and are related to GitHub and the GitHub repository that is used in the current Semaphore 2.0 project.

SEMAPHORE_GIT_SHA

The value of the SEMAPHORE_GIT_SHA environment variable holds the current revision of code that the pipeline is using.

Example values: 5c84719708b9b649b9ef3b56af214f38cee6acde, HEAD

SEMAPHORE_GIT_URL

The value of the SEMAPHORE_GIT_URL environment variable is the URL of the GitHub repository used in the current Semaphore 2.0 project.

Example value: http://git@github.com:semaphoreci/toolbox.git

SEMAPHORE_GIT_BRANCH

The value of the SEMAPHORE_GIT_BRANCH environment variable is the name of the GitHub branch that is used in the current job.

Example value: development

SEMAPHORE_GIT_DIR

The value of the SEMAPHORE_GIT_DIR environment variable is the name of the directory that contains the files of the GitHub repository of the current Semaphore 2.0 project.

Example value: foo

The following environment variables are related to the cache utility. You can find more information about the cache utility at Toolbox reference.

SEMAPHORE_CACHE_USERNAME

The value of the SEMAPHORE_CACHE_USERNAME environment variable is the username that will be used for connecting to the cache server.

Example value: 0614ef08af7a408d8aae45b029ba3bb8

SEMAPHORE_CACHE_URL

The value of the SEMAPHORE_CACHE_URL environment variable is the IP address and the port number of the cache server.

Example value: 94.130.158.146:29920

SEMAPHORE_CACHE_PRIVATE_KEY_PATH

The value of the SEMAPHORE_CACHE_PRIVATE_KEY_PATH environment variable is the path to the file that contains the SSH key to the cache server.

Example value: /home/semaphore/.ssh/semaphore_cache_key

See Also

Still need help? Contact Us Contact Us