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

Add logLevel to support debugging and also reduce default excessive logging

    • Icon: Improvement Improvement
    • Resolution: Fixed
    • Icon: Minor Minor
    • ssh-steps-plugin
    • None
    • Jenkins ver. 2.138.3
      SSH Pipeline Steps 1.1.1

      Hello.

      Is it possible to add something like silent or quiet option for sshCommand/sshScript/sshPut/sshGet?

      For example if I have sshCommand hostname I get this in log:

      Host key checking is off. It may be vulnerable to man-in-the-middle attacks.
      [jsch] Permanently added 'server-name' (RSA) to the list of known hosts.
      Connected to server-name[server-name:22] (SSH-2.0-OpenSSH_5.3)
      Started command server-name#41: sudo -S -p '06a1c9b9-933d-4777-8a15-2eb1ceebdf91' /bin/bash -c 'hostname'
      Providing password for sudo prompt on server-name[server-name:22]
      server-name|06a1c9b9-933d-4777-8a15-2eb1ceebdf91
      server-name|server-name
      Success command server-name#41: sudo -S -p '06a1c9b9-933d-4777-8a15-2eb1ceebdf91' /bin/bash -c 'hostname'
      Disconnected from server-name[server-name:22]
      

      So instead of just getting:  
      server-name

      we have all those usually unnecessary lines.
      Having hostname| then log output is also not readable.

      Thanks,

      Vlad

          [JENKINS-55194] Add logLevel to support debugging and also reduce default excessive logging

          vladaurosh Sure, let me make it as a param, so that we can alter it based on the use case. Thank you for reporting. 

           

          https://github.com/jenkinsci/ssh-steps-plugin/blob/master/src/main/groovy/org/jenkinsci/plugins/sshsteps/SSHService.groovy#L86

          Naresh Rayapati added a comment - vladaurosh Sure, let me make it as a param, so that we can alter it based on the use case. Thank you for reporting.    https://github.com/jenkinsci/ssh-steps-plugin/blob/master/src/main/groovy/org/jenkinsci/plugins/sshsteps/SSHService.groovy#L86

          Vlad Uros added a comment -

          Thanks Naresh.

          If possible, please add as well option to hide server name before command output, for example:
          server-name|command_output

          Vlad Uros added a comment - Thanks Naresh. If possible, please add as well option to hide server name before command output, for example: server-name|command_output

          Naresh Rayapati added a comment - PR: https://github.com/jenkinsci/ssh-steps-plugin/pull/12

          Merged will release it after further testing.

          Naresh Rayapati added a comment - Merged will release it after further testing.

          Released 1.2.0

          Naresh Rayapati added a comment - Released 1.2.0

          Vlad Uros added a comment - - edited

          Hello Naresh.

          Sorry to bother again, I just tried new version of plugin.

          It is a lot better then before however I think one more thing can be fixed here.

          I've configured Remote and set appendName to false, logLevel to 'OFF'.

          Here's what I got executing "date" command:

          Executing command on server_test[server_test]: /bin/bash -c 'date' sudo: true
          8a5430b4-6f23-448f-a9dd-f65ebfca2378
          Mon Jan 14 18:26:16 CST 2019

          While command output is good we still see line "Executing ..." and line 8a5430b4... which is some kind of sudo pass replacement or something.

           

          Is there a way to hide these lines as well and get just command output?

           

          Also sshPut gives something like this:

          Sending a file/directory to server_test[server_test]: from: /tmp/test.log into: /tmp/b5933af2-f344-4478-9664-c859ebd0949

          Any change to hide these as well?

           

          Thanks a lot,

          Vlad

          Vlad Uros added a comment - - edited Hello Naresh. Sorry to bother again, I just tried new version of plugin. It is a lot better then before however I think one more thing can be fixed here. I've configured Remote and set appendName to false, logLevel to 'OFF'. Here's what I got executing "date" command: Executing command on server_test [server_test] : /bin/bash -c 'date' sudo: true 8a5430b4-6f23-448f-a9dd-f65ebfca2378 Mon Jan 14 18:26:16 CST 2019 While command output is good we still see line "Executing ..." and line 8a5430b4... which is some kind of sudo pass replacement or something.   Is there a way to hide these lines as well and get just command output?   Also sshPut gives something like this: Sending a file/directory to server_test [server_test] : from: /tmp/test.log into: /tmp/b5933af2-f344-4478-9664-c859ebd0949 Any change to hide these as well?   Thanks a lot, Vlad

          I have added those log statements explicitly to note the actual command being run, it was intentional, otherwise there would be no clue about the command being run. 

          Naresh Rayapati added a comment - I have added those log statements explicitly to note the actual command being run, it was intentional, otherwise there would be no clue about the command being run. 

          Vlad Uros added a comment -

          Thanks Naresh.

          Any chance to add parameter to hide this as well?

           

          Thanks,

          Vlad

          Vlad Uros added a comment - Thanks Naresh. Any chance to add parameter to hide this as well?   Thanks, Vlad

          Marjo Hartman added a comment - - edited

          Yesterday I updated the plugin in Jenkins and now I have an issue with sshPut:

          When using a scripted pipeline, everything is okay.

          When using a declarative pipeline, two parameters of the sshPut & sshGet functions are mandatory, while they should be optional.

          WorkflowScript: 27: Missing required parameter: "filterBy" @ line 27, column 5.WorkflowScript: 27: Missing required parameter: "filterBy" @ line 27, column 5.    sshPut(

          Declarative pipeline script (left out the details of obieeServer):

          pipeline
          {
          agent
          {
          node

          { label 'master' }

          }

          stages
          {
          stage('test')
          {
          steps

          { writeFile(file: 'tt.txt', text: 'text') sshPut( remote: obieeServer, from: 'tt.txt', into: "/tmp/tt.txt") }

          }
          }
          }
           

          Marjo Hartman added a comment - - edited Yesterday I updated the plugin in Jenkins and now I have an issue with sshPut: When using a scripted pipeline, everything is okay. When using a declarative pipeline, two parameters of the sshPut & sshGet functions are mandatory, while they should be optional. WorkflowScript: 27: Missing required parameter: "filterBy" @ line 27, column 5.WorkflowScript: 27: Missing required parameter: "filterBy" @ line 27, column 5.    sshPut( Declarative pipeline script (left out the details of obieeServer): pipeline { agent { node { label 'master' } } stages { stage('test') { steps { writeFile(file: 'tt.txt', text: 'text') sshPut( remote: obieeServer, from: 'tt.txt', into: "/tmp/tt.txt") } } } }  

          Naresh Rayapati added a comment - - edited

          vladaurosh looks like I need to make a change to make filterBy and filterRegex optional, so I am going to make these log statements off when we set log level to OFF (or just when logLevel is present)

           

          Thank you marjohartman for pointing out that.

          Naresh Rayapati added a comment - - edited vladaurosh  looks like I need to make a change to make filterBy and filterRegex optional, so I am going to make these log statements off when we set log level to OFF (or just when logLevel is present)   Thank you marjohartman for pointing out that.

          Naresh Rayapati added a comment - PR:  https://github.com/jenkinsci/ssh-steps-plugin/pull/15

          Vlad Uros added a comment -

          Thank you very much Naresh.

          It does make sense what you suggested, just to see command output when log level set to OFF.

           

          Vlad Uros added a comment - Thank you very much Naresh. It does make sense what you suggested, just to see command output when log level set to OFF.  

          This has been released 1.2.1, it should available soon in the update center. Thank you vladaurosh and marjohartman for the help reporting this. 

           

          Closing this now, don't mind to reopen or create a new one just in case if there is any issues with this change. Thanks again. 

          Naresh Rayapati added a comment - This has been released 1.2.1, it should available soon in the update center. Thank you vladaurosh and marjohartman for the help reporting this.    Closing this now, don't mind to reopen or create a new one just in case if there is any issues with this change. Thanks again. 

          Vlad Uros added a comment -

          Hello Naresh.

          Sorry to bother again. I just tried latest version, it does look a lot better. But I thinki there's one left over, if sudo is set to true and logLevel is OFF. Still I can see, I would say, some kind of password representation, for example:

          d1d24c36-c6e1-4f0c-8294-8461efacf97c

           

          Can this be hidden as well when logLevel is set to OFF?

           

          Thanks,

          Vlad

          Vlad Uros added a comment - Hello Naresh. Sorry to bother again. I just tried latest version, it does look a lot better. But I thinki there's one left over, if sudo is set to true and logLevel is OFF. Still I can see, I would say, some kind of password representation, for example: d1d24c36-c6e1-4f0c-8294-8461efacf97c   Can this be hidden as well when logLevel is set to OFF?   Thanks, Vlad

          That is an unique id generated for the specific session (nothing related to password or username), unfortunately that is part of underlying library, which I won't be able to alter. Thank you. 

          Naresh Rayapati added a comment - That is an unique id generated for the specific session (nothing related to password or username), unfortunately that is part of underlying library, which I won't be able to alter. Thank you. 

          Vlad Uros added a comment -

          Hello Naresh.

          Sorry for opening this again I tested something and I am a bit confused.  I executed couple of commands with and without sudo.

           

          1. working command without sudo

              sshCommand remote: remote, command: "echo regards" 

             Output is:
          regards

          2. working command with sudo 

             sshCommand sudo: true,remote: remote, command: "echo regards"

             Output is:  
          17362243-a06c-4421-bfb1-c15684b3ffc0
          regards
           

          3. wrong command with sudo

            sshCommand sudo: true,remote: remote, command: "some_command"

            Output is:

           
          9b30df7c-86d7-4bdf-a5ed-f956a1286686
          sudo: some_command: command not found
          I caught exception and it is:

          org.hidetake.groovy.ssh.session.BadExitStatusException: Command returned exit status 1: sudo -S -p '9b30df7c-86d7-4bdf-a5ed-f956a1286686' some_command

           

          So looks like if I use
          remote.logLevel = 'OFF'
          remote.appendName = false

          and sudo is set to false (default)  output is not showing unique id.

          With sudo set to true we see it in output. 

           

          Looking at exception and how sudo is executed options for sudo are:

          -p prompt   The -p (prompt) option allows you to override the default password prompt and use a custom one.

          -S          The -S (stdin) option causes sudo to read the password from the standard input instead of the terminal device.  The password must be followed by a newline character.

           

          sudo -S -p should mean sending password, so 9b30df7c-86d7-4bdf-a5ed-f956a1286686 is somehow related to sudo and password.

          And as you see in output there is 9b30df7c-86d7-4bdf-a5ed-f956a1286686 which is same as in sudo -S -p '9b30df7c-86d7-4bdf-a5ed-f956a1286686'

           

          Maybe I am wrong in this.

           

          Thanks,

          Vlad

          Vlad Uros added a comment - Hello Naresh. Sorry for opening this again I tested something and I am a bit confused.  I executed couple of commands with and without sudo.   1. working command without sudo     sshCommand remote: remote, command: "echo regards"     Output is: regards 2. working command with sudo     sshCommand sudo: true,remote: remote, command: "echo regards"    Output is:   17362243-a06c-4421-bfb1-c15684b3ffc0 regards   3. wrong command with sudo   sshCommand sudo: true,remote: remote, command: "some_command"   Output is:   9b30df7c-86d7-4bdf-a5ed-f956a1286686 sudo: some_command: command not found I caught exception and it is: org.hidetake.groovy.ssh.session.BadExitStatusException: Command returned exit status 1: sudo -S -p '9b30df7c-86d7-4bdf-a5ed-f956a1286686' some_command   So looks like if I use remote.logLevel = 'OFF' remote.appendName = false and sudo is set to false (default)  output is not showing unique id. With sudo set to true we see it in output.    Looking at exception and how sudo is executed options for sudo are: -p prompt   The -p (prompt) option allows you to override the default password prompt and use a custom one. -S          The -S (stdin) option causes sudo to read the password from the standard input instead of the terminal device.  The password must be followed by a newline character.   sudo -S -p should mean sending password, so 9b30df7c-86d7-4bdf-a5ed-f956a1286686 is somehow related to sudo and password. And as you see in output there is 9b30df7c-86d7-4bdf-a5ed-f956a1286686 which is same as in sudo -S -p '9b30df7c-86d7-4bdf-a5ed-f956a1286686'   Maybe I am wrong in this.   Thanks, Vlad

          Yes, you are right, and that is an expected behavior, sudo command prompts for password, so this plugin is opening up a unique session to interact with actual shell command, and those lines are related to that session. 

           

          For the normal command we just logon to box and execute the command, but for the sudo commands we need to logon to box and up on executing the sudo command which prompts for password again, requires someone manually key in the password, which isn't ideal in case of automation and also Jenkins doesn't support shell interactions. 

          Naresh Rayapati added a comment - Yes, you are right, and that is an expected behavior, sudo command prompts for password, so this plugin is opening up a unique session to interact with actual shell command, and those lines are related to that session.    For the normal command we just logon to box and execute the command, but for the sudo commands we need to logon to box and up on executing the sudo command which prompts for password again, requires someone manually key in the password, which isn't ideal in case of automation and also Jenkins doesn't support shell interactions. 

          vladaurosh so what are you expecting.. or what is the use case that has prompted you to ask this question and reopen this JIRA? 

          Naresh Rayapati added a comment - vladaurosh so what are you expecting.. or what is the use case that has prompted you to ask this question and reopen this JIRA? 

          Vlad Uros added a comment -

          Thanks for the explanation Naresh.

          We should be fine to close this now.

          Ideally for me would be not to see for example 9b30df7c-86d7-4bdf-a5ed-f956a1286686 in console output but as you said, it is some other library that is causing it.

           

           

          Vlad Uros added a comment - Thanks for the explanation Naresh. We should be fine to close this now. Ideally for me would be not to see for example 9b30df7c-86d7-4bdf-a5ed-f956a1286686 in console output but as you said, it is some other library that is causing it.    

          Yes, as I mentioned before that is something being printed by dependent library. so I have little control over that one. Thank you. 

          Naresh Rayapati added a comment - Yes, as I mentioned before that is something being printed by dependent library. so I have little control over that one. Thank you. 

            nrayapati Naresh Rayapati
            vladaurosh Vlad Uros
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated:
              Resolved: