[JIRA] (JENKINS-57126) Support alternative drive letters for Windows ssh agents using PowerShell/Win32-OpenSSH

12 views
Skip to first unread message

ray.kivisto@gmail.com (JIRA)

unread,
Apr 20, 2019, 9:35:02 AM4/20/19
to jenkinsc...@googlegroups.com
Ray Kivisto created an issue
 
Jenkins / Improvement JENKINS-57126
Support alternative drive letters for Windows ssh agents using PowerShell/Win32-OpenSSH
Issue Type: Improvement Improvement
Assignee: Ray Kivisto
Components: ssh-slaves-plugin
Created: 2019-04-20 13:34
Environment: jenkins 2.164.2 LTS
SSH Slaves plugin 1.29.4
Master using OpenJDK 1.8.0_151 on Mac OS X Mojave 10.14.4
Agent is an EC2 instance running Windows Server 2012 R2 and Oracle JRE 1.8.0_201
For the Windows agent, I installed https://github.com/PowerShell/Win32-OpenSSH/releases/tag/v7.9.0.0p1-Beta
as per the section "On earlier versions of Windows" and also "Configuring SSH server" from https://winscp.net/eng/docs/guide_windows_openssh_server
Note: I did not install Cygwin on this WIndows agent.
Priority: Minor Minor
Reporter: Ray Kivisto

I was able to successfully connect the Windows machine with PowerShell/Win32-OpenSSH using the "SSH Slaves plugin" using the "Remote root directory" of "C:\jenkins-agent", and I'm able to run Windows builds on this agent.

The issue occurs when I change the "Remote root directory" to "D:\jenkins-agent", then the agent fails to launch:

[04/20/19 09:21:28] [SSH] Remote file system root D:\jenkins-agent does not exist. Will try to create it...

[04/20/19 09:21:28] [SSH] Copying latest remoting.jar...

[04/20/19 09:21:29] [SSH] Copied 789,283 bytes.
Expanded the channel window size to 4MB
[04/20/19 09:21:29] [SSH] Starting agent process: cd "D:\jenkins-agent" && "C:\Program Files (x86)\Java\jre1.8.0_201\bin\java.exe" -jar remoting.jar -workDir D:\jenkins-agent
Error: Unable to access jarfile remoting.jar
Slave JVM has terminated. Exit code=1
[04/20/19 09:21:29] Launch failed - cleaning up connection
[04/20/19 09:21:29] [SSH] Connection closed.

The root cause appears to be that the command 'cd "D:\jenkins-agent"' does not successfully change to the D:\ drive, because when using Windows command prompt, you need to add the '/d' argument to the 'cd' command to change the drive:

/d : Changes the current drive or the current directory for a drive.

Add Comment Add Comment
 
This message was sent by Atlassian Jira (v7.11.2#711002-sha1:fdc329d)

ray.kivisto@gmail.com (JIRA)

unread,
Apr 20, 2019, 10:09:06 AM4/20/19
to jenkinsc...@googlegroups.com
Ray Kivisto commented on Improvement JENKINS-57126
 
Re: Support alternative drive letters for Windows ssh agents using PowerShell/Win32-OpenSSH

I am able to work around this error by adding a "Prefix Start Agent Command" of:

cd /d D:\ &&

Then the agent will connect successfully, and I'm able to run Windows builds on this agent.

ray.kivisto@gmail.com (JIRA)

unread,
Apr 20, 2019, 10:10:01 AM4/20/19
to jenkinsc...@googlegroups.com
Ray Kivisto edited a comment on Improvement JENKINS-57126
I am able to work around this error by adding a "Prefix Start Agent Command" of:

{ quote} { cd /d D:\ &&
{quote
} }

Then the agent will connect successfully, and I'm able to run Windows builds on this agent.

ray.kivisto@gmail.com (JIRA)

unread,
Apr 20, 2019, 10:10:02 AM4/20/19
to jenkinsc...@googlegroups.com
Ray Kivisto updated an issue
 
Change By: Ray Kivisto
Comment:
I am able to work around this error by adding a "Prefix Start Agent Command" of:

{{cd /d D:\ && }}


Then the agent will connect successfully, and I'm able to run Windows builds on this agent.

ray.kivisto@gmail.com (JIRA)

unread,
Apr 20, 2019, 10:10:02 AM4/20/19
to jenkinsc...@googlegroups.com

I am able to work around this error by adding a "Prefix Start Agent Command" of:

cd /d D:\ &&

Then the agent will connect successfully, and I'm able to run Windows builds on this agent.

Add Comment Add Comment
 

robin.jansohn@zf.com (JIRA)

unread,
May 9, 2019, 7:43:02 AM5/9/19
to jenkinsc...@googlegroups.com

+1. Just what I wanted to propose, too! But I'm not sure if it's that easy as the /d switch does not exist on *nix systems as far as I know...

ray.kivisto@gmail.com (JIRA)

unread,
May 13, 2019, 10:53:01 AM5/13/19
to jenkinsc...@googlegroups.com

I have some WIP for my idea how to implement this at https://github.com/jenkinsci/ssh-slaves-plugin/compare/master...rkivisto:alternative-windows-drives

I still need to do additional testing to ensure I don't regress other platforms, and ensure I don't break Windows agents that use the Cygwin installed OpenSSH.

 

ray.kivisto@gmail.com (JIRA)

unread,
Jun 24, 2019, 12:33:02 PM6/24/19
to jenkinsc...@googlegroups.com

I tested my WIP at

   https://github.com/jenkinsci/ssh-slaves-plugin/compare/master...rkivisto:alternative-windows-drives

using Cygwin by following the instructions at:

   https://go.cloudbees.com/docs/cloudbees-core/cloud-admin-guide/agents/#_microsoft_windows

I found that my WIP still needs to take into account when the build agent is using Cygwin OpenSSH, because right now it is passing the "/d" argument to "cd" from Cygwin, and it fails with the message:

  "bash: line 0: cd: too many arguments"

 

I see that there is the environment variable "OSTYPE=cygwin" that is available so I could check if we are using cygwin, but it is not available until after the remoting connection is already established. The problem is, the shell command "cmd" is determined before the remoting connection is established, and is passed to "session.execCommand(cmd);" https://github.com/rkivisto/ssh-slaves-plugin/blob/ca2821bddac099bb6c9e87a721476d92caa5187e/src/main/java/hudson/plugins/sshslaves/SSHLauncher.java#L613

ray.kivisto@gmail.com (JIRA)

unread,
Jun 24, 2019, 12:40:02 PM6/24/19
to jenkinsc...@googlegroups.com
Ray Kivisto edited a comment on Improvement JENKINS-57126
I tested my WIP at

   [https://github.com/jenkinsci/ssh-slaves-plugin/compare/master...rkivisto:alternative-windows-drives]

using Cygwin by following the instructions at:

   [https://go.cloudbees.com/docs/cloudbees-core/cloud-admin-guide/agents/#_microsoft_windows]

I found that my WIP still needs to take into account when the build agent is using Cygwin OpenSSH, because right now it is passing the "/d" argument to "cd" from Cygwin, and it fails with the message:

  "bash: line 0: cd: too many arguments"

 

I see that there is the environment variable "OSTYPE=cygwin" that is available , so I could check if we are using cygwin , but it is not available until after the remoting connection is already established . The problem is, the shell command "cmd" is determined before the remoting connection is established, and is passed to "session.execCommand(cmd);" https://github.com/rkivisto/ssh-slaves-plugin/blob/ca2821bddac099bb6c9e87a721476d92caa5187e/src/main/java/hudson/plugins/sshslaves/SSHLauncher.java#L613

ray.kivisto@gmail.com (JIRA)

unread,
Jun 24, 2019, 5:19:02 PM6/24/19
to jenkinsc...@googlegroups.com

I've implemented cygwin detection, and re-tested the feature.

It's working for me locally and I've submitted a PR:

https://github.com/jenkinsci/ssh-slaves-plugin/pull/134

ray.kivisto@gmail.com (JIRA)

unread,
Jun 25, 2019, 10:56:02 AM6/25/19
to jenkinsc...@googlegroups.com
Ray Kivisto started work on Improvement JENKINS-57126
 
Change By: Ray Kivisto
Status: Open In Progress

ray.kivisto@gmail.com (JIRA)

unread,
Aug 7, 2019, 11:16:02 AM8/7/19
to jenkinsc...@googlegroups.com
Reply all
Reply to author
Forward
0 new messages