How to set the PATH environment variable in Jenkins configuration on Windows?

When I run my build process on Windows Server 2008, it fails with the error message like

Cannot run program "foo": CreateProcess: error=2, The system cannot find the file specified

I've already had a similar issue on Ubuntu Server and resolved it by adding the path to the folder with the binaries installed globally by Composer to the PATH variable in Jenkins config (Manage Jenkins -> Configure System -> Global properties -> Environment variables: name=PATH, value=$PATH:$COMPOSER_HOME/vendor/bin/):

enter image description here

(Due to a permissions moving COMPOSER_HOME outside of the /root directory was also needed to another one, accessible for Jenkins, was also needed.)

Now I tried the same on Windows, but it doesn't work. So, maybe I'm just setting the PATH wrong. What I've tried:

PATH
$PATH:D:\path\to\COMPOSER_HOME\vendor\bin

PATH
$PATH;D:\path\to\COMPOSER_HOME\vendor\bin

PATH
%PATH%D:\path\to\COMPOSER_HOME\vendor\bin

PATH
%PATH%;D:\path\to\COMPOSER_HOME\vendor\bin

How to set the PATH environment variable in Jenkins configs correctly working on Windows?


It needs to be "Path", not "PATH".

Jenkins treats this special variable in a case-sensitive way, and only "Path" is recognized as being the path variable. "PATH" looks to jenkins like a generic environment variable, even on Windows.


The issue I had was caused not by a wrong Path configuration. %PATH%;D:\path\to\COMPOSER_HOME\vendor\bin is correct.

enter image description here


don't get to confused about %PATH% vs $PATH in the Value field. While %PATH% is the correct syntax for windows nodes, you should use /foo/bar:$PATH to extend PATH on unix nodes


I had a similar requirement to customize Path variable on a Windows slave with a Windows Jenkins master. I did not want to create a Jenkins global environment variable and wanted this variable to be specific to a particular windows node/agent.

Here is what I did:

1) Created an Environment Variable as shown below in Nodes -> WindowsNode -> Configure screen:

Nodes -> WindowsNode -> Configure

2) Disconnected my Jenkins node.

3) Restarted my Jenkins system process directly on the slave.

4) Tested it out by clicking on Nodes -> WindowsNode -> System Information and saw the new environment variable assigned to the node:

enter image description here

5) Then used it in a Jenkins job that would run on the Windows slave/agent by adding below command to an Execute Windows Batch Command build step:

git --version


If you want to set it locally for the respective job try this in Build -> Execute batch Command step:

//append more variables separated by ; if required
SET Path=%PATH%;C:\Program Files\Git\bin;

//run your command here
git --version

This approach works for any type of command you wanted to execute. Just add the respective environmental variable to the Path variable locally as shown above.