jenkinsci / jenkinsci/credentials-binding-plugin

[JENKINS-61341] FileNotFoundException if withCredentials([sshUserPrivateKey]) is called twice

Open
#478 9 comments 0 reactions 0 assignees View on GitHub
component:credentials-binding-plugin component:ssh-steps-plugin imported-jira-issue priority:minor resolution:unresolved
Dominant language
Java
Stars
57
Forks
108
PR merge metrics
No merged PRs in 30d

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.

---
Originally reported by theck, imported from: FileNotFoundException if withCredentials([sshUserPrivateKey]) is called twice


  • assignee: nrayapati
  • status: Open
  • priority: Minor
  • component(s): credentials-binding-plugin, ssh-steps-plugin
  • resolution: Unresolved
  • votes: 1
  • watchers: 4
  • imported: 20251211-141027

Raw content of original issue

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.

environment

```
OS: centos

Jenkins: 2.223

OpenJDK 1.8.0_242

credentials-binding: 1.21

ssh-steps: 2.0.0
```

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.