Environment variables
Semaphore variables
These variables describe various aspects of Semaphore workings.
CI
- Environment variable:
CI
- Example:
true
Holds true
when the session runs in a Semaphore continuous integration (CI) environment.
Semaphore
- Environment variable:
SEMAPHORE
- Example:
true
Holds true
when the session is running in a Semaphore environment.
Agent environment type
- Environment variable:
SEMAPHORE_AGENT_MACHINE_ENVIRONMENT_TYPE
- Example:
container
Defines the type of environment for the current job.
Possible values are:
container
: job running inside a Docker containerVM
: job running on a virtual machine
Agent OS image
- Environment variable:
SEMAPHORE_AGENT_MACHINE_OS_IMAGE
- Example:
ubuntu2004
The name of the operating system image active in the current job.
See machine types for all available options.
Agent machine type
- Environment variable:
SEMAPHORE_AGENT_MACHINE_TYPE
- Example:
e1-standard-2
The type of agent running the current job.
See machine types for all available options.
Job creation time
- Environment variable:
SEMAPHORE_JOB_CREATION_TIME
- Example:
1632943641
The UNIX epoch seconds when the current job was created.
Job id
- Environment variable:
SEMAPHORE_JOB_ID
- Example:
a26d42cf-89ac-4c3f-9e2d-51bb231897bf
The unique identifier for the current job. Semaphore automatically generates unique IDs for every job.
You can view all the job IDs using the sem CLI:
- Get active jobs: execute
sem get jobs
- Get most recent jobs: execute
sem get jobs --all
Job name
- Environment variable:
SEMAPHORE_JOB_NAME
- Example:
Push image to Docker
A string with a user-supplied name for the job.
Job count
- Environment variable:
SEMAPHORE_JOB_COUNT
- Example: 4
Only available when job parallelism is enabled. This variable holds the total number of jobs configured in job parallelism.
It can be used to configure a test partitioning strategy using a 3rd party test runner.
Job index
- Environment variable:
SEMAPHORE_JOB_INDEX
- Example: 1
Only available when job parallelism is enabled. This is a 1-based index that represents the current job instance in parallel set. The value ranges between 1 and SEMAPHORE_JOB_COUNT
.
It can be used to configure a test partitioning strategy using a 3rd party test runner.
Job result
- Environment variable:
SEMAPHORE_JOB_RESULT
- Example:
passed
Describes the ending state of the job. The possible states are:
none
: the job has not yet finishedpassed
: the job finished successfullyfailed
: the job finished in failurestopped
: the job was terminated before completion
This variable is only available in the job epilogue.
Job type
- Environment variable:
SEMAPHORE_JOB_TYPE
- Example:
pipeline_job
Describes why the current job was created. The possible values are:
pipeline_job
: a regular job created by Semaphore as part of the workflowproject_debug_job
: job created withsem debug project
debug_job
: job created withsem debug job
Server URL
- Environment variable:
SEMAPHORE_ORGANIZATION_URL
- Example:
https://semaphore.example.com
The URL for the server that owns the project running the current job.
Pipeline ID
- Environment variable:
SEMAPHORE_PIPELINE_ID
- Example:
ea3e6bba-d19a-45d7-86a0-e78a2301b616
The unique identifier for the current workflow. All jobs that belong to the same pipeline share the same ID.
Pipeline is rerun
- Environment variable:
SEMAPHORE_PIPELINE_RERUN
- Example:
true
Holds true
when the pipeline is rerun by the user.
Project ID
- Environment variable:
SEMAPHORE_PROJECT_ID
- Example:
0dd982e8-32f5-4037-983e-4de01ac7fb1e
The project unique identifier that the job session belongs to. Semaphore automatically assigns unique IDs to every project.
Project name
- Environment variable:
SEMAPHORE_PROJECT_NAME
- Example:
my-awesome-project
The name of the project that a job belongs to.
Workflow ID
- Environment variable:
SEMAPHORE_WORKFLOW_ID
- Example:
0dd982e8-32f5-4037-983e-4de01ac7fb1e
The workflow unique identifier. All jobs belonging to all pipelines in the workflow share this same ID. This includes the initial pipeline and all manually or auto-promoted pipelines in the same build.
Workflow number
- Environment variable:
SEMAPHORE_WORKFLOW_NUMBER
- Example:
42
This number is incremented every time the workflow runs. In other words, the number is incremented by one every time there is a Git push on any branch, every time there is a pull request, or a tag is pushed to the repository. It doesn't increment with debug jobs.
This number is available to all jobs in all pipelines belonging to the same workflow. This includes the initial pipeline and all manually or auto-promoted pipelines in the same build.
Workflow is rerun
- Environment variable:
SEMAPHORE_WORKFLOW_RERUN
- Example:
true
Holds true
if the workflow is a rerun of a previously-ran workflow.
Workflow triggered by
- Environment variable:
SEMAPHORE_WORKFLOW_TRIGGERED_BY
- Example:
torvalds
Determines the GitHub or BitBucket username for the individual who promoted the pipeline.
Workflow is triggered by API
- Environment variable:
SEMAPHORE_WORKFLOW_TRIGGERED_BY_API
- Example:
true
Holds true
if the workflow was triggered using the Semaphore API
The variable is false
if the workflow is triggered by a Git push, pull request, or via Tasks.
Workflow is triggered by hook
- Environment variable:
SEMAPHORE_WORKFLOW_TRIGGERED_BY_HOOK
- Example:
true
Holds true
if the workflow was triggered by a Git push to the repository. It's also true for Git tags and pull requests.
The variable is false
when the workflow is triggered via the Semaphore API or using Tasks.
Workflow is triggered manually
- Environment variable:
SEMAPHORE_WORKFLOW_TRIGGERED_BY_MANUAL_RUN
- Example:
true
Holds true
if the workflow was triggered by a user through the Semaphore UI.
The variable is false
when the workflow is triggered by Git push, pull request, Tasks, or the Semaphore API.
Workflow is triggered by task
- Environment variable:
SEMAPHORE_WORKFLOW_TRIGGERED_BY_SCHEDULE
- Example:
true
Holds true
if the workflow was triggered using Tasks.
Git repository variables
These variables give Git-related information about the repository that is liked to the project the job is running.
Branch (upstream)
- Environment variable:
SEMAPHORE_GIT_BRANCH
- Example:
main
The Git branch is used in the current job. On pull requests, the value is the name of the upstream branch targeted by the merge.
For example, if you create a branch called featureA
and create a pull request to merge to main
, then SEMAPHORE_GIT_BRANCH=main
.
Working branch (downstream)
- Environment variable:
SEMAPHORE_GIT_WORKING_BRANCH
- Example:
featureA
The name of the branch used in the current job. On pull request, this is the downstream branch that would be merged.
For example, if you create a branch called featureA
and create a pull request to merge to main
, then SEMAPHORE_GIT_WORKING_BRANCH=featureA
.
The variable is missing when the workflow is triggered by pushing the Git tag.
Commit author
- Environment variable:
SEMAPHORE_GIT_COMMIT_AUTHOR
- Example:
torvalds
The GitHub or Bitbucket username of the person who authored the revision.
Commit range
- Environment variable:
SEMAPHORE_GIT_COMMIT_RANGE
- Example:
5c84719708b9b649b9ef3b56af214f38cee6acde...92d87d5c0dd2dbb7a68ecb27df43d1b164fd3e30
The range of SHA commits that were included in a push or pull request.
This is empty for builds triggered by the initial commit of a new branch or tag.
Commit SHA
- Environment variable:
SEMAPHORE_GIT_SHA
- Example:
5c84719708b9b649b9ef3b56af214f38cee6acde
The current Git SHA revision of the code that the job is using.
Cache age
- Environment variable:
SEMAPHORE_GIT_CACHE_AGE
- Example:
259200
Used only when running checkout --use-cache
. It specifies how often the Semaphore Git Cache is updated, expressed in seconds. The default is 259200 (3 days).
Cache keep
- Environment variable:
SEMAPHORE_GIT_CACHE_KEEP
- Example:
1
Used only when running checkout --use-cache
. It how many copies of the repository should be maintained in the Semaphore Git Cache. Older copies are automatically deleted.
The default value is 0, which means that Semaphore maintains only 1 copy of the repository. If you set it to 1, Semaphore will maintain 2 copies of the repository.
Committer
- Environment variable:
SEMAPHORE_GIT_COMMITTER
- Example:
torvalds
The GitHub or Bitbucket username of the person who authored the revision.
Depth
- Environment variable:
SEMAPHORE_GIT_DEPTH
- Example:
50
Holds the shallow clone depth level for the checkout command. The default value is 50.
Git provider
- Environment variable:
SEMAPHORE_GIT_PROVIDER
- Example:
bitbucket
,github
The Git provider the repository is hosted on. Possible values are bitbucket
or github
.
Git reference
- Environment variable:
SEMAPHORE_GIT_REF
- Example:
refs/heads/master
The Git reference the commit that the job is using.