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

sshCommand fails to flush full log on failure

XMLWordPrintable

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

      I have a Jenkins job where I'm running Ansible through sshCommand:

      sshCommand remote: remote, command: "ansible-playbook lb.yml"

      However, if the last step of this Ansible playbook fails, the plugin throws an exception, but doesn't print the error logs for that final step. Running it normally in a shell would print additional logs.

      Jenkins log:

      TASK [lb : Configure nginx conf] ******************************************
      changed: [server]
      TASK [lb : Restart nginx] *************************************************
      [Pipeline] }
      [Pipeline] // withCredentials
      [Pipeline] }
      [Pipeline] // stage
      [Pipeline] }
      [Pipeline] // withEnv
      [Pipeline] }
      [Pipeline] // node
      [Pipeline] End of Pipeline
      Also: hudson.remoting.Channel$CallSiteStackTrace: Remote call to JNLP4-connect connection from <server-ip>
              at hudson.remoting.Channel.attachCallSiteStackTrace(Channel.java:1741)
              at hudson.remoting.UserRequest$ExceptionResponse.retrieve(UserRequest.java:356)
              at hudson.remoting.Channel.call(Channel.java:955)
              at org.jenkinsci.plugins.sshsteps.steps.CommandStep$Execution.run(CommandStep.java:72)
              at org.jenkinsci.plugins.sshsteps.util.SSHStepExecution.lambda$start$0(SSHStepExecution.java:84)
      ... (additional stack trace lines omitted)
      org.hidetake.groovy.ssh.session.BadExitStatusException: Command returned exit status 2: ansible-playbook lb.yml
      

      Shell log:

      TASK [lb : Configure nginx conf] ******************************************
      changed: [server]
      TASK [lb : Restart nginx] *************************************************
      fatal: [server]: FAILED! => {"changed": false, "msg": "Unable to start service nginx: Job for nginx.service failed because the control process exited with error code.\nSee \"systemctl status nginx.service\" and \"journalctl -xe\" for details.\n"}
      	to retry, use: --limit @/ansible/lb.retry
      
      PLAY RECAP ****************************************************************
      server   : ok=1   changed=0    unreachable=0    failed=1   
      

      I checked, and all of these log lines go to stdout.

      These additional log lines are necessary for debugging the issue (the workaround right now is to try executing the ansible script directly from the node, which isn't great) so it would be great to flush them before throwing this BadExitStatusException. 

            nrayapati Naresh Rayapati
            jiangtyd Damien J
            Votes:
            5 Vote for this issue
            Watchers:
            11 Start watching this issue

              Created:
              Updated: