How I can execute Windows Commands on remote server using the Jenkins Declarative Pipeline?

Hi,

can someone suggest me a method how I can execute in Jenkins Declarative Pipeline remote windows commands (e.g. using the cmd or powershell) with some already existing Jenkins Plugin? The remote machine is not an agent, but the machine where some deployment using the FTP is being done after which I need to execute command for Windows Service restart.
How this can be achieved? I thought that maybe WinRMClient plugin can be used for these purposes but I cannot execute it on my Linux docker agent (I have a separate topic open for this issue.)

I would be thankful for useful hints!
Thanks a lot

I don’t think you need (or want) a dedicated plugin for that task. If you can execute a command from Linux that runs something on your Windows computer, then you can run that command inside a Jenkins Pipeline. Some examples of techniques that are available to run a Windows command remotely from Linux include:

  • Secure shell - install and configure Microsoft’s OpenSSH server on your Windows computer, use ssh to start Windows programs from Linux
  • winexe - install Linux winexe command and use it to start Windows programs from Linux
  • xfreerdp - install Linux xfreerdp command and use it to start Windows programs from Linux
1 Like

Mark, thanks a lot for your very kind assistance. I wen through the links you provided me and I was wondering if you have some additional link with instructions for the: SSH installation and configuration for OpenSSH on windows. I suppose that assumes that we need to generate some keys, certificates, exchange files etc. Would it be possible to give me the best link which describes these steps in details? Thanks!!!

I use the Microsoft documentation for OpenSSH

In my environment we found that running a Jenkins agent was not a bad thing and this integrates nicely with a pipeline.

1 Like