Environment Variables

Artifakt environment variables are available during application runtime. This allows you to customize an environments behavior or to use information you don’t want to save in your repository.

Introduction

We know that an application must be able to run on several environments in parallel: development environments (on local or non-local machines), test environments, production environments, etc. If all these environments are based on the same source code, specific configurations are required for each of them. For example, the access credentials to your payment processor will be different between the test environments and your production.

This specific configuration must be stored in environment variables. Unlike other methods, such as configuration files, environment variables are unlikely to be accidentally revealed in your Git repository. In addition, this method allows you to change the configuration of each environment in isolation.

Define Custom variables

Environment Level Variables

To add custom variables on an environment, go to Project β†’ Settings β†’ Application. The variables defined will be specific to this environment. Please note that the defined variables will be specific to the modified environment.

Configuring environment variables

An environment variable defined as "Masked" will not be displayed in the logs, unlike other environment variables.

Job Level Variables

In order to offer a high level of flexibility, Artifakt also allows you to define environment variables at the job level.

These variables are specific to the current job, which means that they will only be accessible in the execution context of this job.

Pre-defined Artifakt Variables

In addition to the variables you define, Artifakt has a number of pre-defined variables built in. When adding new additional services (MySQL, Redis, ...) new variables are available.

The following variables are automatically set and available during build step and runtime. These variables cannot be overwritten.

General

Variable

Description

ARTIFAKT_ENVIRONMENT_NAME

Name of the environment.

ARTIFAKT_ENVIRONMENT_CRITICALITY

Environment criticality (prod for a critical environment, dev for a noncritical environment ).

ARTIFAKT_BUILD_ID

Identifier of the last built container image. Designed to ensure same code version runs on all servers

ARTIFAKT_IS_MAIN_INSTANCE

Indicates whether the machine is the main Web server.

Elasticsearch Service

Variable

Description

ARTIFAKT_ES_HOST

Host name of the Elasticsearch server.

ARTIFAKT_ES_PORT

Port to be used to connect to the Elasticsearch server.

MySQL Service

Variable

Description

ARTIFAKT_MYSQL_HOST

Host name of the MySQL database of the environment.

ARTIFAKT_MYSQL_PORT

Port to be used to connect to the MySQL database.

ARTIFAKT_MYSQL_USER

MySQL user login.

ARTIFAKT_MYSQL_PASSWORD

MySQL user password.

ARTIFAKT_MYSQL_DATABASE_NAME

Name of the database.

Redis Service

Variable

Description

ARTIFAKT_REDIS_HOST

Host name of the Redis server.

ARTIFAKT_REDIS_PORT

Port to be used to connect to the Redis server.

If you need a specific variable which is not listed above, do not hesitate to submit your feedback.

Read Environment Variables

Environment variables defined at the environment level are available:

  • inside the containers

  • when custom callbacks are triggered (build.sh and entrypoint.sh)

  • while executing any job

Environment variables defined at the job level are available:

  • while executing the current job

  • when custom callbacks are triggered (if any) (build.sh and entrypoint.sh)

PHP

echo 'My environment name is ' . $_ENV["ARTIFAKT_ENVIRONMENT_NAME"];

Bash

echo $ARTIFAKT_ENVIRONMENT_NAME