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

FileNotFoundException if withCredentials([sshUserPrivateKey]) is called twice

    XMLWordPrintable

    Details

    • Similar Issues:

      Description

      Hi.

      I am currently working on a Jenkins pipeline and trying to move all credential handling in the domain of the jenkins instance.

      To be able to execute an ssh command on another machine we use private key authentication. I tried to accomplish this by combining credentials-binding and ssh-steps but ran into a problem I couldn't find a solution to.

      I basicly do this:
       

      node {
          def remote = [:]
          remote.name = "integration_server"
          remote.host = integration_server
          remote.allowAnyHosts = true
      
          withCredentials([sshUserPrivateKey(credentialsId: 'myCredentialId', keyFileVariable: 'identity', passphraseVariable: '', usernameVariable: 'userName')]) {
              remote.user = userName
              remote.identityFile = identity
              sshCommand remote: remote, command: "do stuff"
          }
      
      ...
      
          withCredentials([sshUserPrivateKey(credentialsId: 'myCredentialId', keyFileVariable: 'identity', passphraseVariable: '', usernameVariable: 'userName')]) {
              remote.user = userName
              remote.identityFile = identity
              sshCommand remote: remote, command: "do some other stuff"
          }
      }
      

      The first block runs fine. The second block fails with a FileNotFoundException looking for a temporary "secretFile".
      My guess is, that credential-binding reuses the reference to the temporary file from the first block during execution of the second block while simultaniously deleting it after the first block ends.

      I would like to be able to define multiple indipendent withCredential steps to omit wrapping the whole script in one large block.

        Attachments

          Activity

          theck Timo Heck created issue -
          julian_alarcon Julian Alarcon made changes -
          Field Original Value New Value
          Component/s ssh-steps-plugin [ 23921 ]
          julian_alarcon Julian Alarcon made changes -
          Assignee Naresh Rayapati [ nrayapati ]

            People

            Assignee:
            nrayapati Naresh Rayapati
            Reporter:
            theck Timo Heck
            Votes:
            1 Vote for this issue
            Watchers:
            4 Start watching this issue

              Dates

              Created:
              Updated: