Uploaded image for project: 'Jenkins'
  1. Jenkins
  2. JENKINS-75006

Connect to Windows sshCommand via SSH in Jenkins pipeline to execute bat. The bat executed when canceling the task the bat does not exit

    • Icon: Bug Bug
    • Resolution: Unresolved
    • Icon: Major Major
    • ssh-steps-plugin
    • None

      1、jenkins pipeline job:

      script:

      def getRemoteServer(name, host, port, credentialId){
          def remote = [:]
          remote.name = name
          remote.host = host
          remote.port = port
          remote.allowAnyHosts = true
          withCredentials([usernamePassword(credentialsId: credentialId, passwordVariable: "password", usernameVariable: "userName")]) {
              remote.user = "${userName}"
              remote.password = "${password}"
          }
          return remote
      }

      pipeline {
          agent any

          stages {
              stage('Hello') {
                steps{
                  script{
                    scriptPath="D:/script"
                    remotePath = "D:/software"
                    dir(scriptPath){
                      script_file="${JOB_NAME}.bat"
                      script_text="@echo off\n" +
      '''
      ping -t 127.0.0.1
      '''
                      remote = getRemoteServer("server local", "127.0.0.1", 22, "a514b136-4e85-4d94-89a4-9a624d8a6ba3")
                      writeFile file: "${script_file}", encoding: "UTF-8", text: script_text.replace('\r\n', '\n').replace('\r', '\n').replace('\n', '\r\n')
                      sshPut remote: remote, from: "./${script_file}", into: "/${remotePath}/${script_file}"
                      sshCommand remote: remote, command: "${remotePath}/${script_file}"
                    }
                  }
                }
              }
          }
      }

       

       

      2、start the job:test5,and canceling

       
      Started by user jason_lo
      Running on Jenkins in D:\Tools\Jenkins\.jenkins\workspace\test5
      Running in G:/script
      Masking supported pattern matches of %userName% or %password%
      Sending a file/directory to server local[127.0.0.1]: from: G:/script\test5.bat into: /G:/software/test5.bat
      Executing command on server local[127.0.0.1]: G:/software/test5.bat sudo: false

      Pinging 127.0.0.1 with 32 bytes of data:
      Reply from 127.0.0.1: bytes=32 time<1ms TTL=128
      Reply from 127.0.0.1: bytes=32 time<1ms TTL=128
      Reply from 127.0.0.1: bytes=32 time<1ms TTL=128
      Aborted by jason_lo
      org.jenkinsci.plugins.workflow.actions.ErrorAction$ErrorId: 9e09c5ee-63bf-4399-b25a-5d6ef54e22f5
      java.lang.InterruptedException
      at java.base/java.lang.Object.wait(Native Method)
      at java.base/java.lang.Thread.join(Thread.java:1304)
      at java.base/java.lang.Thread.join(Thread.java:1372)
      at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
      at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:77)
      at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
      at java.base/java.lang.reflect.Method.invoke(Method.java:568)
      at org.codehaus.groovy.reflection.CachedMethod.invoke(CachedMethod.java:98)
      at groovy.lang.MetaMethod.doMethodInvoke(MetaMethod.java:325)
      at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:1225)
      at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:1034)
      at org.codehaus.groovy.runtime.InvokerHelper.invokePojoMethod(InvokerHelper.java:935)
      at org.codehaus.groovy.runtime.InvokerHelper.invokeMethod(InvokerHelper.java:926)
      at org.codehaus.groovy.runtime.ScriptBytecodeAdapter.invokeMethodN(ScriptBytecodeAdapter.java:181)
      at org.codehaus.groovy.runtime.ScriptBytecodeAdapter.invokeMethodNSafe(ScriptBytecodeAdapter.java:189)
      at org.codehaus.groovy.runtime.ScriptBytecodeAdapter.invokeMethodNSpreadSafe(ScriptBytecodeAdapter.java:196)
      at org.codehaus.groovy.runtime.ScriptBytecodeAdapter.invokeMethod0SpreadSafe(ScriptBytecodeAdapter.java:211)
      at PluginClassLoader for ssh-steps//org.hidetake.groovy.ssh.interaction.Interactions.waitForEndOfStream(Interactions.groovy:97)
      at org.hidetake.groovy.ssh.interaction.Interactions$waitForEndOfStream$1.call(Unknown Source)
      at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:47)
      at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:116)
      at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:120)
      at PluginClassLoader for ssh-steps//org.hidetake.groovy.ssh.operation.Command.execute(Command.groovy:83)
      at org.hidetake.groovy.ssh.operation.Operation$execute$0.call(Unknown Source)
      at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:47)
      at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:116)
      at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:120)
      at PluginClassLoader for ssh-steps//org.hidetake.groovy.ssh.session.execution.Command$Helper.execute(Command.groovy:50)
      at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
      at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:77)
      at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
      at java.base/java.lang.reflect.Method.invoke(Method.java:568)
      at org.codehaus.groovy.reflection.CachedMethod.invoke(CachedMethod.java:98)
      at org.codehaus.groovy.runtime.callsite.StaticMetaMethodSite$StaticMetaMethodSiteNoUnwrapNoCoerce.invoke(StaticMetaMethodSite.java:151)
      at org.codehaus.groovy.runtime.callsite.StaticMetaMethodSite.call(StaticMetaMethodSite.java:91)
      at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:47)
      at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:116)
      at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:144)
      at PluginClassLoader for ssh-steps//org.hidetake.groovy.ssh.session.execution.Command$Trait$Helper.execute(Command.groovy:30)
      at org.hidetake.groovy.ssh.session.execution.Command$Trait$Helper$execute$0.call(Unknown Source)
      at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:47)
      at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:116)
      at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:144)
      at PluginClassLoader for ssh-steps//org.hidetake.groovy.ssh.session.SessionHandler.execute(SessionHandler.groovy)
      at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
      at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:77)
      at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
      at java.base/java.lang.reflect.Method.invoke(Method.java:568)
      at org.codehaus.groovy.runtime.callsite.PogoMetaMethodSite$PogoCachedMethodSite.invoke(PogoMetaMethodSite.java:169)
      at org.codehaus.groovy.runtime.callsite.PogoMetaMethodSite.call(PogoMetaMethodSite.java:71)
      at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:47)
      at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:116)
      at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:136)
      at PluginClassLoader for ssh-steps//org.hidetake.groovy.ssh.session.execution.Command$Trait$Helper.execute(Command.groovy)
      at org.hidetake.groovy.ssh.session.execution.Command$Trait$Helper$execute.call(Unknown Source)
      at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:47)
      at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:116)
      at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:136)
      at PluginClassLoader for ssh-steps//org.hidetake.groovy.ssh.session.SessionHandler.execute(SessionHandler.groovy)
      at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
      at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:77)
      at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
      at java.base/java.lang.reflect.Method.invoke(Method.java:568)
      at org.codehaus.groovy.reflection.CachedMethod.invoke(CachedMethod.java:98)
      at groovy.lang.MetaMethod.doMethodInvoke(MetaMethod.java:325)
      at org.codehaus.groovy.runtime.metaclass.ClosureMetaClass.invokeMethod(ClosureMetaClass.java:352)
      at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:1034)
      at org.codehaus.groovy.runtime.callsite.PogoMetaClassSite.callCurrent(PogoMetaClassSite.java:68)
      at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCallCurrent(CallSiteArray.java:51)
      at org.codehaus.groovy.runtime.callsite.AbstractCallSite.callCurrent(AbstractCallSite.java:157)
      at org.codehaus.groovy.runtime.callsite.AbstractCallSite.callCurrent(AbstractCallSite.java:169)
      at PluginClassLoader for ssh-steps//org.jenkinsci.plugins.sshsteps.SSHService$_executeCommand_closure3$_closure13.doCall(SSHService.groovy:182)
      at PluginClassLoader for ssh-steps//org.jenkinsci.plugins.sshsteps.SSHService$_executeCommand_closure3$_closure13.doCall(SSHService.groovy)
      at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
      at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:77)
      at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
      at java.base/java.lang.reflect.Method.invoke(Method.java:568)
      at org.codehaus.groovy.reflection.CachedMethod.invoke(CachedMethod.java:98)
      at groovy.lang.MetaMethod.doMethodInvoke(MetaMethod.java:325)
      at org.codehaus.groovy.runtime.metaclass.ClosureMetaClass.invokeMethod(ClosureMetaClass.java:264)
      at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:1034)
      at org.codehaus.groovy.runtime.callsite.PogoMetaClassSite.call(PogoMetaClassSite.java:41)
      at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:47)
      at org.codehaus.groovy.runtime.callsite.PogoMetaClassSite.call(PogoMetaClassSite.java:56)
      at PluginClassLoader for ssh-steps//org.hidetake.groovy.ssh.util.Utility.callWithDelegate(Utility.groovy:17)
      at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
      at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:77)
      at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
      at java.base/java.lang.reflect.Method.invoke(Method.java:568)
      at org.codehaus.groovy.reflection.CachedMethod.invoke(CachedMethod.java:98)
      at groovy.lang.MetaMethod.doMethodInvoke(MetaMethod.java:325)
      at org.codehaus.groovy.runtime.callsite.StaticMetaMethodSite.invoke(StaticMetaMethodSite.java:46)
      at org.codehaus.groovy.runtime.callsite.StaticMetaMethodSite.callStatic(StaticMetaMethodSite.java:102)
      at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCallStatic(CallSiteArray.java:55)
      at org.codehaus.groovy.runtime.callsite.StaticMetaMethodSite.callStatic(StaticMetaMethodSite.java:104)
      at org.codehaus.groovy.runtime.callsite.AbstractCallSite.callStatic(AbstractCallSite.java:217)
      at PluginClassLoader for ssh-steps//org.hidetake.groovy.ssh.session.SessionTask.wetRun(SessionTask.groovy:64)
      at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
      at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:77)
      at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
      at java.base/java.lang.reflect.Method.invoke(Method.java:568)
      at org.codehaus.groovy.runtime.callsite.PogoMetaMethodSite$PogoCachedMethodSiteNoUnwrapNoCoerce.invoke(PogoMetaMethodSite.java:210)
      at org.codehaus.groovy.runtime.callsite.PogoMetaMethodSite.callCurrent(PogoMetaMethodSite.java:59)
      at org.codehaus.groovy.runtime.callsite.AbstractCallSite.callCurrent(AbstractCallSite.java:161)
      at PluginClassLoader for ssh-steps//org.hidetake.groovy.ssh.session.SessionTask.call(SessionTask.groovy:48)
      at java_util_concurrent_Callable$call.call(Unknown Source)
      at PluginClassLoader for ssh-steps//org.hidetake.groovy.ssh.core.Service.run(Service.groovy:81)
      at org.hidetake.groovy.ssh.core.Service$run$0.call(Unknown Source)
      at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:47)
      at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:116)
      at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:128)
      at PluginClassLoader for ssh-steps//org.jenkinsci.plugins.sshsteps.SSHService.executeCommand(SSHService.groovy:177)
      at PluginClassLoader for ssh-steps//org.jenkinsci.plugins.sshsteps.steps.CommandStep$Execution$CommandCallable.execute(CommandStep.java:84)
      at PluginClassLoader for ssh-steps//org.jenkinsci.plugins.sshsteps.util.SSHMasterToSlaveCallable.call(SSHMasterToSlaveCallable.java:32)
      at hudson.remoting.LocalChannel.call(LocalChannel.java:46)
      at PluginClassLoader for ssh-steps//org.jenkinsci.plugins.sshsteps.steps.CommandStep$Execution.run(CommandStep.java:72)
      at PluginClassLoader for ssh-steps//org.jenkinsci.plugins.sshsteps.util.SSHStepExecution.lambda$start$0(SSHStepExecution.java:84)
      at java.base/java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:539)
      at java.base/java.util.concurrent.FutureTask.run(FutureTask.java:264)
      at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1136)
      at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:635)
      at java.base/java.lang.Thread.run(Thread.java:833)
      Finished: ABORTED
       

      3、the bat does not exit, running。

       

          [JENKINS-75006] Connect to Windows sshCommand via SSH in Jenkins pipeline to execute bat. The bat executed when canceling the task the bat does not exit

          Jason created issue -
          Jason made changes -
          Priority Original: Minor [ 4 ] New: Blocker [ 1 ]
          Jason made changes -
          Priority Original: Blocker [ 1 ] New: Major [ 3 ]

            nrayapati Naresh Rayapati
            jason_lo Jason
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated: