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

Throw appropriate error when the code is not in node block

    • Icon: Improvement Improvement
    • Resolution: Fixed
    • Icon: Minor Minor
    • ssh-steps-plugin
    • None

      The pipeline example for sshCommand provided in the Github page is wrong, it gives a NullPointException in my installation:

      java.lang.NullPointerException
      	at org.jenkinsci.plugins.sshsteps.steps.CommandStep$Execution.run(CommandStep.java:71)
      	at org.jenkinsci.plugins.sshsteps.util.SSHStepExecution$1$1.call(SSHStepExecution.java:77)
      	at hudson.security.ACL.impersonate(ACL.java:290)
      	at org.jenkinsci.plugins.sshsteps.util.SSHStepExecution$1.run(SSHStepExecution.java:72)
      	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)
      	at java.lang.Thread.run(Thread.java:748)
      Finished: FAILURE

      However, after adding pipelines, stages and steps wrappers around it, it worked fine:

      def remote = [:]
      remote.name = 'test'
      remote.host = 'test.domain.com'
      remote.user = 'root'
      remote.password = 'password'
      remote.allowAnyHosts = true
      pipeline { 
          agent any 
          stages {
              stage('SSH') {
                  steps{
                      sshCommand remote: remote, command: "ls -l /"
                  }
              }
          }
      }
      

          [JENKINS-52390] Throw appropriate error when the code is not in node block

          Cassio Binkowski created issue -
          Cassio Binkowski made changes -
          Description Original: The pipeline example for _sshCommand_ provided in the Github page is wrong, it gives a NullPointException in my installation.

          However, after adding pipelines and stages wrapper around it, it worked fine.

           
          {code:java}
          def remote = [:]
          remote.name = 'test'
          remote.host = 'test.domain.com'
          remote.user = 'root'
          remote.password = 'password'
          remote.allowAnyHosts = true
          pipeline {
              agent any
              stages {
                  stage('SS') {
                      steps{
                          sshCommand remote: remote, command: "ls -l /"
                      }
                  }
              }
          }
          {code}
          New: The pipeline example for _sshCommand_ provided in the Github page is wrong, it gives a NullPointException in my installation:
          {noformat}
          java.lang.NullPointerException
          at org.jenkinsci.plugins.sshsteps.steps.CommandStep$Execution.run(CommandStep.java:71)
          at org.jenkinsci.plugins.sshsteps.util.SSHStepExecution$1$1.call(SSHStepExecution.java:77)
          at hudson.security.ACL.impersonate(ACL.java:290)
          at org.jenkinsci.plugins.sshsteps.util.SSHStepExecution$1.run(SSHStepExecution.java:72)
          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)
          at java.lang.Thread.run(Thread.java:748)
          Finished: FAILURE{noformat}
          However, after adding pipelines, stages and steps wrappers around it, it worked fine:
          {code:java}
          def remote = [:]
          remote.name = 'test'
          remote.host = 'test.domain.com'
          remote.user = 'root'
          remote.password = 'password'
          remote.allowAnyHosts = true
          pipeline {
              agent any
              stages {
                  stage('SSH') {
                      steps{
                          sshCommand remote: remote, command: "ls -l /"
                      }
                  }
              }
          }
          {code}

          cassioiks That was a scripted pipeline example, needs to be called in node as in example at [1]. Thanks for reporting, I will update all of these examples while working on JENKINS-52226

          node {
            def remote = [:]
            remote.name = 'test'
            remote.host = 'test.domain.com'
            remote.user = 'root'
            remote.password = 'password'
            remote.allowAnyHosts = true
            stage('Remote SSH') {
              sshCommand remote: remote, command: "ls -lrt"
              sshCommand remote: remote, command: "for i in {1..5}; do echo -n \"Loop \$i \"; date ; sleep 1; done"
            }
          }
          

          [1] https://github.com/jenkinsci/ssh-steps-plugin#withcredentials

          Naresh Rayapati added a comment - cassioiks That was a scripted pipeline example, needs to be called in node as in example at [1] . Thanks for reporting, I will update all of these examples while working on JENKINS-52226 node { def remote = [:] remote.name = 'test' remote.host = 'test.domain.com' remote.user = 'root' remote.password = 'password' remote.allowAnyHosts = true stage( 'Remote SSH' ) { sshCommand remote: remote, command: "ls -lrt" sshCommand remote: remote, command: " for i in {1..5}; do echo -n \" Loop \$i \ "; date ; sleep 1; done" } } [1] https://github.com/jenkinsci/ssh-steps-plugin#withcredentials
          Naresh Rayapati made changes -
          Summary Original: Example in Github is incorrect New: Throw appropriate error when the code is not in node block

          Made a pull request to throw appropriate error instead of throwing  java.lang.NullPointerException

          https://github.com/jenkinsci/ssh-steps-plugin/pull/3

          CC: ghenkes wuchenwang

          Naresh Rayapati added a comment - Made a pull request to throw appropriate error instead of throwing  java.lang.NullPointerException https://github.com/jenkinsci/ssh-steps-plugin/pull/3 CC: ghenkes wuchenwang
          Naresh Rayapati made changes -
          Status Original: Open [ 1 ] New: In Progress [ 3 ]
          Naresh Rayapati made changes -
          Status Original: In Progress [ 3 ] New: In Review [ 10005 ]

          Merged above pull request, will release it along with 1.0.1

          Thanks again for reporting! cassioiks

          Naresh Rayapati added a comment - Merged above pull request, will release it along with 1.0.1 Thanks again for reporting! cassioiks
          Naresh Rayapati made changes -
          Resolution New: Fixed [ 1 ]
          Status Original: In Review [ 10005 ] New: Resolved [ 5 ]
          Naresh Rayapati made changes -
          Issue Type Original: Bug [ 1 ] New: Improvement [ 4 ]

            nrayapati Naresh Rayapati
            cassioiks Cassio Binkowski
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved: