Keywords: Jenkins | Windows | PATH | environment variables | configuration
Abstract: This article explains how to correctly set the PATH environment variable in Jenkins on Windows to resolve build failures caused by missing executables. It covers the specific case sensitivity issue and provides step-by-step instructions.
Introduction
When deploying Jenkins on Windows, developers often encounter issues with environment variables, particularly the PATH variable, which can lead to build failures. This article addresses a common problem where Jenkins cannot find executable files due to incorrect PATH settings.
Problem Analysis
The error message "Cannot run program 'foo': CreateProcess: error=2, The system cannot find the file specified" indicates that Jenkins is unable to locate the specified program in the system's PATH. This issue is similar to one resolved on Ubuntu by adding a path to the PATH variable in Jenkins configuration.
On Windows, the challenge arises from Jenkins' handling of the PATH variable. As noted in the community answers, Jenkins treats the PATH variable in a case-sensitive manner on Windows, unlike the native Windows environment where it is case-insensitive.
Solution
To correctly set the PATH environment variable in Jenkins on Windows, follow these steps:
- Navigate to Jenkins configuration:
Manage Jenkins -> Configure System -> Global properties -> Environment variables. - Add a new environment variable with the name
Path(note the capital P). - For the value, use the format:
%PATH%;D:\path\to\COMPOSER_HOME\vendor\bin. This appends the new path to the existing PATH variable.
For example, if COMPOSER_HOME is located at D:\Composer, the value should be %PATH%;D:\Composer\vendor\bin.
Why It Works
Jenkins, being a Java application, has its own environment variable management. On Windows, it specifically recognizes the variable named Path (with a capital P) as the system PATH. Using PATH (all caps) is treated as a generic variable and does not affect the executable search path.
This behavior is documented in Jenkins' internal handling, where the Path variable is used to construct the runtime environment for builds.
Best Practices
Always use the correct case for environment variables in Jenkins. Additionally, ensure that the paths added are accessible and correctly formatted with semicolons as separators on Windows. After setting the variable, restart the Jenkins service or reload the configuration to apply changes.