What are environmental variables?
Environment variables are key-value pairs that contain information about the system environment. In Jenkins, those variables may be configured globally or at the job level, providing us with a way to customize and parameterize our builds.
Here are some key elements of environmental variables that are described below in detail:
1. Naming and Structure
- Environment variables consist of a name and a value, generally known as a key-value pair.
- The name is mostly in uppercase, and it is conventionally written in uppercase letters with underscores separating every word (for example, PATH, JAVA_HOME).
- The value is the data associated with the variable, which can be a string, a numeric value, or a more complex data type.
2. Scope
Environment variables can have different kinds of scopes:
- Global: As the name suggests, they are available globally, affecting all processes and users.
- User-specific: They are limited to a particular user environment.
- Process-Specific: Valid only for the duration of a particular process.
3. Common Environment Variables:
- PATH: The path specifies directories where the operating system needs to look for executable files.
- HOME or USERPROFILE: It represents the user’s home directory.
- JAVA_HOME: It points towards the installation directory of the Java Development Kit (JDK).
- TMP, or TEMP: Specifies the temporary directory for storing files.
4. Accessing Environment Variables:
In maximum programming languages, gaining access to environment variables is straightforward Process.
Bash (Unix/Linux): In unix/linux it can accessed through this command:
echo $VARIABLE_NAME
PowerShell (Windows): In Windows it can accessed through this command:
$env:VARIABLE_NAME
Python: In Python it can accessed through this command:
os.Environ['VARIABLE_NAME']
JavaScript (Node.Js): In Javascript it can accessed through this command:
process.env.VARIABLE_NAME
How To Set Environment Variables In Jenkins ?
Jenkins is a widely used open-source automation server that facilitates continuous integration and continuous delivery (CI/CD) processes. One powerful feature of Jenkins is its capability to configure environment variables, which are important for various functions like defining parameters, paths, and settings required by numerous jobs and build processes. In this article, we are going to discuss how we can set environment variables in Jenkins to enhance the efficiency of your automation workflows.
Contact Us