Self-hosted Agents Settings
This page describes all the settings available to configure self-hosted agents.
Overview
Self-hosted agents accept configuration settings in three ways. In order of precedence:
- command line arguments: used when starting the agent, e.g.
agent start --endpoint <semaphore-server-url>
- environment variables: supplied when starting the agent. All configuration variable names are prefixed with
SEMAPHORE_AGENT
. So, for example the--disconnect-after-job
argument is transformed intoSEMAPHORE_AGENT_DISCONNECT_AFTER_JOB
- configuration file: using the
--config
option when starting the agent, e.g.agent start --config config.yml
Configuration parameters
This section describes the available configuration parameters.
Endpoint
- argument name:
endpoint
- mandatory: yes
- default value: Empty string
- environment variable:
SEMAPHORE_AGENT_ENDPOINT
This is the endpoint the agent connects to to register, sync, and pull job information. This is your the same as your server URL.
Token
- argument name:
token
- mandatory: yes
- default value: Empty string
- environment variable:
SEMAPHORE_AGENT_TOKEN
This is the unique token generated by Semaphore during agent registration. The registration token is used to validate and secure access to your Semaphore server.
Agent name
- argument name:
name
- mandatory: no
- default value: Empty string
- environment variable:
SEMAPHORE_AGENT_NAME
Agents generate a random name when this argument is empty. Set this value to force a specific name for this agent. The name length must be between 8 and 64 characters.
A pre-signed AWS STS GetCallerIdentity URL can also be used if the agent type] allows it.
Environment variables
- argument name:
env-vars
- mandatory: no
- default value: Empty array
- environment variable:
SEMAPHORE_AGENT_ENV_VARS
Environment variables to pass to the agent's job. This is a way of exposing secrets to your jobs via an agent, instead of using Semaphore secrets.
Command line argument --env-vars
expects a comma-separated list of VAR=VALUE
. For example:
agent start \
--endpoint <semaphore-server-url> \
--token "..." \
--env-vars VAR1=A,VAR2=B
On configuration files, the agent expects an array of strings using. For example:
endpoint: "<semaphore-server-url>"
token: "..."
env-vars:
- VAR1=A
- VAR2=B
Files
- argument name:
files
- mandatory: no
- default value: Empty array
- environment variable:
SEMAPHORE_AGENT_FILES
You can inject files into the job environment when running Docker containers. This is another way of exposing secrets to your jobs via an agent, instead of using Semaphore secrets.
On command line usage --files
the agent expects a comma-separated list of /host/path:/container/path
. For example:
agent start \
--endpoint <semaphore-server-url> \
--token "..." \
--files /tmp/host/file1:/tmp/container/file1,/tmp/host/file2:/tmp/container/file2
With the configuration file, the agent expects an array of strings. For example
endpoint: "<semaphore-server-url>"
token: "..."
files:
- /tmp/host/file1:/tmp/container/file1
- /tmp/host/file2:/tmp/container/file2
Fail on missing files
- argument name:
fail-on-missing-files
- mandatory: no
- default value: false
- environment variable:
SEMAPHORE_AGENT_FAIL_ON_MISSING_FILES
When true, it causes missing files to fail the job without starting. Leave as false to continue jobs even when the files are not found.
Fail on pre-job hook error
- argument name:
fail-on-pre-job-hook-error
- mandatory: no
- default value: false
- environment variable:
SEMAPHORE_AGENT_FAIL_ON_PRE_JOB_HOOK_ERROR
Controls whether the agent should fail the job if the pre-job hook configured with --pre-job-hook-path
fails execution. By default, the job continues normally even if the pre-job hook fails.
Disconnect after job
- argument name:
disconnect-after-job
- mandatory: no
- default value: false
- environment variable:
SEMAPHORE_AGENT_DISCONNECT_AFTER_JOB
When true, the agent will disconnect from Semaphore and shut down after completing a job. Leave false to allow the agent to remain online waiting for new jobs.
Disconnect after idle timeout
- argument name:
disconnect-after-idle-timeout
- mandatory: no
- default value: 0
- environment variable:
SEMAPHORE_AGENT_DISCONNECT_AFTER_IDLE_TIMEOUT
If 0, the agent never disconnects due to idleness. To force disconnection after a set duration in seconds, initialize this argument to a value greater than 0.
Upload job logs
- argument name:
upload-job-logs
- mandatory: no
- default value: never
- environment variable:
SEMAPHORE_AGENT_UPLOAD_JOB_LOGS
This setting controls if the job logs are to be uploaded to the job artifact storage. There are three possible options:
never
: job logs are never uploadedwhen-trimmed
: job logs are only uploaded if they were trimmed for exceeding the 16MB limitalways
: job logs are always uploaded
The logs are uploaded to the path agent/job_logs.txt
in the job artifact storage.
The agent uses the artifact CLI to upload the logs to Semaphore. If the artifact CLI is not available to the agent, nothing will be uploaded.
When the job logs exceed 100MB, they are compressed for better efficiency. The following command can be used to decompress it: gunzip -c {file} > decompressed-file.txt