jenkinsci / jenkinsci/agent-setup-plugin

[JENKINS-23674] environment variable updated in slave's "node properties" works with "Execute Windows batch command", but not with "Execute shell"

Open
#110 0 comments 0 reactions 0 assignees View on GitHub
component:build-environment-plugin component:slave-setup-plugin imported-jira-issue priority:minor resolution:unresolved
Dominant language
Java
Stars
11
Forks
23
Avg merge
21h 13m
Merged PRs (30d)
1

Description

I configure a Windows slave, using "Start Slave as a Windows Service" method. In Node Properties, I add the following entry to update the PATH environment variable to include the Cygwin path (which is not added to the PATH on the slave machine itself):

Node properties: Environment variables

List of key-value pairs

name PATH

value c:\cygwin\bin;$PATH

So, this seems to take affect and work as expected when I have a Jenkins job that adds, in the Build section, an entry for "Execute Windows batch command" . My test simply says to do a "set", so that I can look at the PATH, and then a call to Cygwin command from the Cygwin bin directory, namely the "sh" command.

echo hi 1 from .bat. Do a set to look at path.

set

echo hi 2 from .bat after set command showing Cygwin is in the path. Now call Cygwin sh.

sh -c "echo hi 3 from a Cygwin shell under .bat"

echo bye, sh call is over.

As mentioned above, it works as expected , although the PATH variable seems to have been updated with what I asked for twice:

---Start

....

Path=c:\cygwin\bin;c:\cygwin\bin;C:\Windows\system32;C:\Windows;... etc

....

c:\cygwin\local\builds\workspace\test shell call to windows cygwin machine>sh -c "echo hi 3 from a Cygwin shell under .bat"

hi 3 from a Cygwin shell under .bat

— Done

However, when I try to execute a sh command directly, via a Build step "Execute shell", I get the following error indicating that the PATH variable does NOT include the update I added.

[test shell call to windows cygwin machine] $ sh -xe C:\Users\beinfra\AppData\Local\Temp\hudson2056278742015919827.sh

The system cannot find the file specified

FATAL: command execution failed

java.io.IOException: Cannot run program "sh" (in directory "c:\cygwin\local\builds\workspace\test shell call to windows cygwin machine"): CreateProcess error=2, The system cannot find the file specified.

This is a problem since if I wish to use a multi-configuration job for both Windows and Unix slaves, then the multi-config job needs to execute the same build step "Execute shell" for both Windows and UNIX slaves, and this step does not work for the Windows slave. (I'm also aware of the Xshell plugin, but am not using that for a different reason). If my Windows machine's environment is updated to include the Cygwin\bin in its default path, then the Execute Shell works. I will attach the jobs config.cml, and the log, and the slaves section of Jenkins config.xml

---
Originally reported by rickybobpat, imported from: environment variable updated in slave's "node properties" works with "Execute Windows batch command", but not with "Execute shell"


  • assignee: kohsuke
  • status: Open
  • priority: Minor
  • component(s): build-environment-plugin, slave-setup-plugin
  • resolution: Unresolved
  • votes: 0
  • watchers: 1
  • imported: 20251216-225446

Raw content of original issue

I configure a Windows slave, using "Start Slave as a Windows Service" method. In Node Properties, I add the following entry to update the PATH environment variable to include the Cygwin path (which is not added to the PATH on the slave machine itself):

Node properties: Environment variables

List of key-value pairs
name PATH
value c:\cygwin\bin;$PATH

So, this seems to take affect and work as expected when I have a Jenkins job that adds, in the Build section, an entry for "Execute Windows batch command" . My test simply says to do a "set", so that I can look at the PATH, and then a call to Cygwin command from the Cygwin bin directory, namely the "sh" command.

echo hi 1 from .bat. Do a set to look at path.
set
echo hi 2 from .bat after set command showing Cygwin is in the path. Now call Cygwin sh.
sh -c "echo hi 3 from a Cygwin shell under .bat"
echo bye, sh call is over.

As mentioned above, it works as expected , although the PATH variable seems to have been updated with what I asked for twice:
---Start
....
Path=c:\cygwin\bin;c:\cygwin\bin;C:\Windows\system32;C:\Windows;... etc
....
c:\cygwin\local\builds\workspace\test shell call to windows cygwin machine>sh -c "echo hi 3 from a Cygwin shell under .bat"
hi 3 from a Cygwin shell under .bat
— Done

However, when I try to execute a sh command directly, via a Build step "Execute shell", I get the following error indicating that the PATH variable does NOT include the update I added.

[test shell call to windows cygwin machine] $ sh -xe C:\Users\beinfra\AppData\Local\Temp\hudson2056278742015919827.sh
The system cannot find the file specified
FATAL: command execution failed
java.io.IOException: Cannot run program "sh" (in directory "c:\cygwin\local\builds\workspace\test shell call to windows cygwin machine"): CreateProcess error=2, The system cannot find the file specified.

This is a problem since if I wish to use a multi-configuration job for both Windows and Unix slaves, then the multi-config job needs to execute the same build step "Execute shell" for both Windows and UNIX slaves, and this step does not work for the Windows slave. (I'm also aware of the Xshell plugin, but am not using that for a different reason). If my Windows machine's environment is updated to include the Cygwin\bin in its default path, then the Execute Shell works. I will attach the jobs config.cml, and the log, and the slaves section of Jenkins config.xml

environment

```
Master: Windows 2008R2, IBM Java 1.6

slave: Windows 2008 R2, IBM Java 1.6
```

3 attachments

- [config.xml](https://issues.jenkins.io/secure/attachment/26337/config.xml)
- [log](https://issues.jenkins.io/secure/attachment/26339/log)
- [slave_config.xml](https://issues.jenkins.io/secure/attachment/26338/slave_config.xml)

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.