jenkinsci / jenkinsci/github-branch-source-plugin

[JENKINS-60714] Cannot create jenkins ssh username with private key credential via rest xml api

Open
#1,292 10 comments 0 reactions 0 assignees View on GitHub
component:credentials-plugin component:github-branch-source-plugin imported-jira-issue priority:minor resolution:unresolved
Dominant language
Java
Stars
217
Forks
398
Avg merge
30m
Merged PRs (30d)
1

Description

Basically, I am trying to create a credential on jenkins via Rest API. Using xml data below:

```





GLOBAL

jenkins-github-ssh

jenkins-github-ssh

username



----BEGIN OPENSSH PRIVATE KEY----

*****************************************

----END OPENSSH PRIVATE KEY----





```

I can see the [credential][1] after calling REST post request. But when I use this credential for a GitHub repository, Jenkins says:

>Failed to connect to repository : Command "git ls-remote -h – git@​github.com:***.git HEAD" returned status code 128:

stdout:

stderr: Load key "/tmp/ssh3978703187838467164.key": invalid format

git@​github.com: Permission denied (publickey).

fatal: Could not read from remote repository.

But If I update the credential which is created by rest api with same private key above manually. It works. Somehow key is broken while posting, which seems to be a bug.

 

Do you guys have any idea to point me to a workaround?

Jenkins 2.198 & SSH Credentials Plugin 1.17.3

Thanks

[1]: https://i.stack.imgur.com/j7Ncg.png

---
Originally reported by samthebest, imported from: Cannot create jenkins ssh username with private key credential via rest xml api


  • status: Open
  • priority: Minor
  • component(s): credentials-plugin, github-branch-source-plugin
  • resolution: Unresolved
  • votes: 1
  • watchers: 8
  • imported: 2025-12-02

Raw content of original issue

Basically, I am trying to create a credential on jenkins via Rest API. Using xml data below:

```
<?xml version='1.0' encoding='UTF-8'?>
<com.cloudbees.jenkins.plugins.sshcredentials.impl.BasicSSHUserPrivateKey>
<scope>GLOBAL</scope>
<id>jenkins-github-ssh</id>
<description>jenkins-github-ssh</description>
<username>username</username>
<directEntryPrivateKeySource>
<privateKey>----BEGIN OPENSSH PRIVATE KEY----
*****************************************
----END OPENSSH PRIVATE KEY----</privateKey>
</directEntryPrivateKeySource>
</com.cloudbees.jenkins.plugins.sshcredentials.impl.BasicSSHUserPrivateKey>
```

I can see the [credential][1] after calling REST post request. But when I use this credential for a GitHub repository, Jenkins says:

>Failed to connect to repository : Command "git ls-remote -h – git@github.com:***.git HEAD" returned status code 128:
stdout:
stderr: Load key "/tmp/ssh3978703187838467164.key": invalid format
git@github.com: Permission denied (publickey).
fatal: Could not read from remote repository.

But If I update the credential which is created by rest api with same private key above manually. It works. Somehow key is broken while posting, which seems to be a bug.

 

Do you guys have any idea to point me to a workaround?

Jenkins 2.198 & SSH Credentials Plugin 1.17.3

Thanks

[1]: https://i.stack.imgur.com/j7Ncg.png

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.