What are the environment variables in Jenkins?

Environment variables are key and value pairs, use globally across projects, pipelines, and jobs. Define once and reuse in many places to avoid conflicts. Furthermore, provides security to maintain user authentication configurations as variables. Below are used as an environment variable

  • Environment-specific details such as Development, Stage, and Production configuration
  • Email Configurations such as Hostnames, SMTP configurations
  • Build parameters
  • Docker and Cloud-specific configurations

How to Add environment variables in Jenkins

Multiple ways to set Environment variables in Jenkins.

Use Global System Configuration

  • Go to Dashboard
  • Select Manage Jenkins and Choose System under the System configuration Section as shown below picture

Jenkins Global Environment Variables

  • It opens the Configuration Settings Page
  • Under Global Properties, Check Environment Variables, It shows Add button as given below

Global Environment Variables properties

  • On Clicking Add Button, it shows Two input boxes for the Name and Value fields.
  • Type Name and value pairs and click on Save.It supports multiple environment variables.

Environment Injector Plugin

  • Select Manage Jenkins
  • Select Plugins
  • Choose Available Plugins
  • Type Environment Injector in the Plugins Search box
  • Select the plugin, Download and install it with or without restart.
  • Once Installed, Ready to use it.
  • You can add environment variables

How to view all Environment variables

Environment variables are read using an URL provided Access the below URL and It contains all system and Jenkins-related variables

http://localhost:8080/env-vars.html/

It lists all predefined and custom environment variables. All Environment variables