如何通过ssh step插件中的sshScript在远程Windows计算机上运行bat脚本

我在从服务器上创建了一个非常简单的script.bat文件。 如果我通过sshPut发送并通过sshCommand执行它,则成功。 但是,如果我尝试通过sshScript直接发送并运行脚本,则它会失败并出现异常。

script.bat文件仅包含一个dir命令。

请注意,remote映射与传递给sshPut或sshCommand的映射完全相同。 另外,在尝试通过sshScript发送和执行它之前,我从远程删除了script.bat文件,以确保没有冲突。 我试图通过git bash命令行上的ssh命令运行.bat文件:

ssh -l <loginname> <winhost> 'script.bat'

等待,它要求输入密码并运行bat文件。

作为一项额外的测试,我做了完全相同的操作(使用sshScript远程运行的文本文件中的一个简单的ls命令),但使用了Linux远程计算机,并且运行没有问题。

// This is OK
sshPut remote: remote,from: "script.bat",into: '.'
sshCommand remote: remote,command: '.\\script.bat'
sshCommand remote: remote,command: 'del .\\script.bat'
// This fails
sshScript remote: remote,command: '.\\script.bat'

在远程Windows主机上使用sshScript时,脚本不会执行,并显示以下跟踪信息:

hudson.remoting.Channel$CallSiteStackTrace: Remote call to JNLP4-connect connection from 10.225.122.90/10.225.122.90:44864
        at hudson.remoting.Channel.attachCallSiteStackTrace(Channel.java:1743)
        at hudson.remoting.UserRequest$ExceptionResponse.retrieve(UserRequest.java:357)
        at hudson.remoting.Channel.call(Channel.java:957)
        at org.jenkinsci.plugins.sshsteps.steps.ScriptStep$Execution.run(ScriptStep.java:81)
        at org.jenkinsci.plugins.sshsteps.util.SSHStepExecution.lambda$start$0(SSHStepExecution.java:84)
        at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
        at java.util.concurrent.Futuretask.run(Futuretask.java:266)
        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
org.hidetake.groovy.ssh.session.BadExitStatusException: Command returned exit status 1: /bin/sh
    at sun.reflect.NativeConstructoraccessorImpl.newInstance0(Native Method)
    at sun.reflect.NativeConstructoraccessorImpl.newInstance(NativeConstructoraccessorImpl.java:62)
    at sun.reflect.DelegatingConstructoraccessorImpl.newInstance(DelegatingConstructoraccessorImpl.java:45)
    at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
    at org.codehaus.groovy.reflection.CachedConstructor.invoke(CachedConstructor.java:83)
    at org.codehaus.groovy.reflection.CachedConstructor.doConstructorInvoke(CachedConstructor.java:77)
    at org.codehaus.groovy.runtime.callsite.ConstructorSite$ConstructorSiteNoUnwrap.callConstructor(ConstructorSite.java:84)
    at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCallConstructor(CallSiteArray.java:60)
    at org.codehaus.groovy.runtime.callsite.AbstractCallSite.callConstructor(AbstractCallSite.java:235)
    at org.codehaus.groovy.runtime.callsite.AbstractCallSite.callConstructor(AbstractCallSite.java:255)
    at org.hidetake.groovy.ssh.session.execution.Command$Helper.execute(Command.groovy:52)
...etc...
shi443213174 回答:如何通过ssh step插件中的sshScript在远程Windows计算机上运行bat脚本

暂时没有好的解决方案,如果你有好的解决方案,请发邮件至:iooj@foxmail.com
本文链接:https://www.f2er.com/3151660.html

大家都在问