Gopherbot Environment Variables
Gopherbot makes extensive use of environment variables, both for configuring the robot and plugins, and for providing parameters to external scripts. This article describes the various environment variables and their use; for the environment applicable to a given running task, see per-task environment.
Robot Execution Environment
Certain environment variables can be supplied to the running Gopherbot process to configure and/or bootstrap your robot. These environment variables can be set by:
systemd
- Not recommended; while systemd can provide environment variables to your robot, it's very insecure and will allow local users on the system to view the valuesdocker
,docker-compose
or Kubernetes - these and other container environments provide more secure means of providing environment variables to containers$GOPHER_HOME/.env
- the most secure means of providing environment variables to your robot is creating a.env
file in$GOPHER_HOME
, outside of any git repository, mode0600
The last two options are recommended for production deployments of a Gopherbot robot.
Start-up Environment
The following values can be provided to your robot on start-up:
GOPHER_ENCRYPTION_KEY
- 32+ character encryption key used for decrypting thebinary-encrypted-key
GOPHER_CUSTOM_REPOSITORY
- clone URL for the robot's custom configuration, used in bootstrappingGOPHER_CUSTOM_BRANCH
- branch to use if other thanmaster
GOPHER_LOGFILE
- where to write out a log fileGOPHER_CONFIGDIR
- absolute or relative path to configuration directoryGOPHER_DEPLOY_KEY
- ssh deploy key for cloning the custom repository
For the optional state
and private
repositories, the included jobs will use the GOPHER_CUSTOM_REPOSITORY
value with s/gopherbot/state/
and s/gopherbot/private/
(same branch). If desired, the values can also be supplied:
GOPHER_STATE_REPOSITORY
- repository holding state, normally just a file-backed brain, defaults to$GOPHER_CUSTOM_REPOSITORY
androbot-state
branchGOPHER_STATE_BRANCH
- ifGOPHER_STATE_REPOSITORY
is set, this defaults tomaster
, otherwiserobot-state
GOPHER_PRIVATE_REPOSITORY
- non-public repository withenvironment
, for dev onlyGOPHER_PRIVATE_BRANCH
- branch to use if other thanmaster
Configuration Environment Variables
Gopherbot normally takes almost all of it's configuration from the collection of *.yaml
files in the custom configuration directory, but for easy flexibility, a collection of environment variables are referenced in the default configuration. These are some of the values that are expanded; the actual configuration files are the definitive reference.
GOPHER_PROTOCOL
- used to select a non-default protocol (e.g. "terminal")GOPHER_LOGLEVEL
- error, warn, info, debug, traceGOPHER_BOTNAME
- the name the robot will answer to, e.g. "floyd"GOPHER_ALIAS
- the one-character alias for the robot, e.g. ";"GOPHER_BOTMAIL
- the robot's email addressGOPHER_BOTFULLNAME
- the robot's full nameGOPHER_HISTORYDIR
- directory for storing file-based historical job logsGOPHER_WORKSPACE
- workspace directory where e.g. build jobs clone and runGOPHER_BRAIN
- non-default brain provider to useGOPHER_STATEDIR
- default dir for storing state, normally just the brainGOPHER_BRAIN_DIRECTORY
- directory where file-based memories are stored, overrides aboveGOPHER_JOBCHANNEL
- where jobs run by default if not otherwise specifiedGOPHER_TIMEZONE
- UNIX tz, e.g. "America/New_York" (default)
External Script Environment
Gopherbot always scrubs the environment when executing tasks, so environment variables set on execution are not automatically passed to child processes. The only environment variables that are passed through from original execution are:
HOME
- this should rarely be used; for portable robots, useGOPHER_HOME
, insteadHOSTNAME
LANG
PATH
- this should be used with care since it can make your robot less portableUSER
In addition to the above passed-through environment vars, Gopherbot supplies the following environment variables to external scripts:
GOPHER_INSTALLDIR
- absolute path to the gopherbot install, normally/opt/gopherbot
RUBYLIB
- path for Rubyrequire 'gopherbot_v1'
, normally/opt/gopherbot/lib
PYTHONPATH
- path for Pythonimport
, normally/opt/gopherbot/lib
Automatic Environment Variables
During startup, Gopherbot will examine it's environment and potentially set values for a few environment variables to support the bootstrap and setup plugins, and simplify common operations.
First, Gopherbot will check for custom configuration or the presence of a GOPHER_CUSTOM_REPOSITORY
environment variable. In the absence of either, the following will be automatically set:
GOPHER_UNCONFIGURED
- set trueGOPHER_LOGFILE
- set to "robot.log" if not already setGOPHER_PROTOCOL
- set to "terminal" so the default robot will start
If no custom configuration is present but GOPHER_CUSTOM_REPOSITORY
is set:
GOPHER_PROTOCOL
- set to "nullconn", the null connector, to allow the bootstrap plugin to bootstrap your robot
If the robot is configured but GOPHER_PROTOCOL
isn't set:
GOPHER_PROTOCOL
- set to "terminal" for local operationsGOPHER_LOGFILE
- set to "robot.log" if not already set
Finally, if encryption is initialized on start-up, GOPHER_ENCRYPTION_INITIALIZED
will be set to true
, regardless of whether the robot is configured.
Pipeline Environment Variables
The following environment variable are set for all pipelines, whether started by a plugin or a job:
GOPHER_CHANNEL
- the channel where the plugin/job is providing outputGOPHER_CHANNEL_ID
- the protocol channel IDGOPHER_MESSAGE_ID
- the opaque message id of the matching messageGOPHER_THREAD_ID
- an opaque string value identifying the conversation threadGOPHER_THREADED_MESSAGE
- set "true" if the message was received in a threadGOPHER_USER
- the user whose message created the pipeline (if any)GOPHER_PROTOCOL
- the name of the protocol in use, e.g. "slack"GOPHER_BRAIN
- the type of brain in useGOPHER_ENVIRONMENT
- "production", unless overriddenGOPHER_PIPE_NAME
- the name of the plugin or job that started the pipelineGOPHER_TASK_NAME
- the name of the running taskGOPHER_PIPELINE_TYPE
- the event type that started the current pipeline, one of:plugCommand
- direct robot command, notrun job ...
plugMessage
- ambient message matchedcatchAll
- catchall plugin ranjobTrigger
- triggered by a JobTriggerscheduled
- started by a ScheduledTaskjobCommand
- started fromrun job ...
command
The following are also supplied whenever a job is run:
GOPHER_JOB_NAME
- the name of the running jobGOPHER_START_CHANNEL
- the channel where the job was startedGOPHER_START_CHANNEL_ID
- the protocol ID for the channel where the job was startedGOPHER_START_MESSAGE_ID
- the opaque message id for the message that started the jobGOPHER_START_THREAD_ID
- the opaque thread id where the job was startedGOPHER_START_THREADED_MESSAGE
- whether the job was started from a message in a threadGOPHER_REPOSITORY
- the extended namespace fromrepositories.yaml
, if anyGOPHER_LOG_LINK
- link to job log, if non-ephemeralGOPHER_LOG_REF
- log reference used for email log and tail log commands
The following are set at the end of the main pipeline, and can be referenced in final and fail tasks:
GOPHER_FINAL_TASK
- name of final task that ran in the pipelineGOPHER_FINAL_TYPE
- type of last task to run, one of "task", "plugin", "job"GOPHER_FINAL_COMMAND
- if type == "plugin", set to the plugin commandGOPHER_FINAL_ARGS
- space-separated list of arguments to final taskGOPHER_FINAL_DESC
-Description:
of final taskGOPHER_FAIL_CODE
- numeric return value if final task failedGOPHER_FAIL_STRING
- string value of robot.TaskRetVal returned
Pipelines and tasks that have Homed: true
and/or Privileged: true
may also get:
GOPHER_HOME
- absolute path to the startup directory for the robot, relative paths are relative to this directory; unset ifcwd
can't be determinedGOPHER_WORKSPACE
- the workspace directory (normally relative toGOPHER_HOME
)GOPHER_CONFIGDIR
- absolute path to custom configuration directory, normally$GOPHER_HOME/custom
GopherCI Environment Variables
In addition to the environment variables set by the Gopherbot engine, the localbuild
GopherCI builder sets the following environment variables that can be used to modify pipelines:
GOPHERCI_BRANCH
- the branch being built (GOPHER_REPOSITORY
is set byExtendNamespace
)GOPHERCI_DEPBUILD
- set to "true" if the build was triggered by a dependencyGOPHERCI_DEPREPO
- the updated repository that triggered this buildGOPHERCI_DEPBRANCH
- the updated branchGOPHERCI_CUSTOM_PIPELINE
- pipeline being run if other than "pipeline"