Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to use jenkins crediential plugin api #162

Closed
wulonghui opened this issue Dec 28, 2014 · 11 comments
Closed

How to use jenkins crediential plugin api #162

wulonghui opened this issue Dec 28, 2014 · 11 comments

Comments

@wulonghui
Copy link

Does jenkins crediential plugin support restapi , how to create credientials by ruby client?
Any example?

@wulonghui
Copy link
Author

I tried the method to create crediential as the post gave , but it doesnot work.

post_params = {
          "name" => "testcred",
          "description" => "test cred description",
          "json" => {
            "domainCredentials" => {
              "domain" => {
                "name" => "",
                "description" => "",
              },
              "credentials" => {
                "scope" => "GLOBAL",
                "id" => "",
                "username" => "root",
                "description" => "root users credential",
                "privateKeySource" => {
                  "value" => "0",
                  "privateKey" => "blah blah blah",
                  "stapler-class" => "com.cloudbees.jenkins.plugins.sshcredentials.impl.BasicSSHUserPrivateKey$DirectEntryPrivateKeySource"
                },
                "passphrase" => "",
                "stapler-class" => "com.cloudbees.jenkins.plugins.sshcredentials.impl.BasicSSHUserPrivateKey",
                "kind" => "com.cloudbees.jenkins.plugins.sshcredentials.impl.BasicSSHUserPrivateKey"
              }
            }
          }.to_json
        }
@client.api_post_request("/credentials/configSumbit", post_params)

Jenkins ver. 1.550
Credentials Plugin 1.9.3

@arangamani
Copy link
Owner

@wulonghui I haven't tried the Jenkins credentials plugin API yet. I'll let you know what I find.

@wulonghui
Copy link
Author

@arangamani Thanks in advance

@ghost
Copy link

ghost commented Apr 13, 2015

I'm also looking for a way to create a new credential via the REST API (or even the cli). It looks like it should be somewhere in https://github.com/jenkinsci/credentials-plugin/ but I'm not familiar enough with jenkins to figure it out.

http://stackoverflow.com/questions/29616660/how-to-create-jenkins-credentials-via-the-rest-api

@goindwalia
Copy link

I am looking for the same @dachary , let me know if you have figured out this.

@rG8KDQ5YXlJ7fcE80CLmNx
Copy link

@wulonghui Hitting an endpoint that actually exists may help.
Try: "/credentials/configSubmit" instead of "/credentials/configSumbit"
I've tested on Jenkins 1.619 and it works fine.

@wulonghui
Copy link
Author

@rG8KDQ5YXlJ7fcE80CLmNx Thanks

@luisfernandos
Copy link

luisfernandos commented Jun 23, 2016

Try this:

curl -X POST 'http://user:token@jenkins_server:8080/credentials/store/system/domain/_/createCredentials'
--data-urlencode 'json={
"": "0",
"credentials": {
"scope": "GLOBAL",
"id": "identification",
"username": "manu",
"password": "bar",
"description": "linda",
"$class": "com.cloudbees.plugins.credentials.impl.UsernamePasswordCredentialsImpl"
}
}'

@jurgenweber
Copy link

jurgenweber commented Oct 10, 2017

I am having the same issue but just trying to do it bash, it will not accept my privateKey value.

Caused: java.lang.IllegalArgumentException: Failed to convert the privateKeySource parameter of the constructor public com.cloudbees.jenkins.plugins.sshcredentials.impl.BasicSSHUserPrivateKey(com.cloudbees.plugins.credentials.CredentialsScope,java.lang.String,java.lang.String,com.cloudbees.jenkins.plugins.sshcredentials.impl.BasicSSHUserPrivateKey$PrivateKeySource,java.lang.String,java.lang.String) any ideas?

How are you formatting the private key inside its value?

@gothiyag
Copy link

gothiyag commented Feb 1, 2018

There is a problem with SSH private_key direct posting. when i post it with ssh private key, it is removing "+" sign from the content. Am using ansible for this.

  • name: configure ssh credential
    uri:
    url: "https://{{ host_ip }}/credentials/store/system/domain/_/createCredentials"
    method: POST
    headers:
    Content-Type: "application/x-www-form-urlencoded"
    Accept: "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,/;q=0.8"
    Accept-Encoding: "gzip, deflate, br"
    others: "--data-urlencode"
    body: 'json={"": "6",
    "credentials": {
    "scope": "GLOBAL",
    "username": "{{ ssh_cred.value.username }}",
    "privateKeySource": {
    "value": "0",
    "privateKey": "-----BEGIN RSA PRIVATE KEY-----
    /abbhsshsnne +bbbebe
    ----END RSA PRIVATE KEY-----",
    "stapler-class": "com.cloudbees.jenkins.plugins.sshcredentials.impl.BasicSSHUserPrivateKey$DirectEntryPrivateKeySource"
    },
    "passphrase": "{{ ssh_cred.value.passphrase }}",
    "id": "{{ ssh_cred.value.id }}",
    "description": "{{ ssh_cred.value.description }}",
    "stapler-class": "com.cloudbees.jenkins.plugins.sshcredentials.impl.BasicSSHUserPrivateKey",
    "$class": "com.cloudbees.jenkins.plugins.sshcredentials.impl.BasicSSHUserPrivateKey"
    }
    }'
    validate_certs: no
    follow_redirects: yes
    register: login
    return_content: yes
    with_dict: "{{ ssh_credentials }}"
    loop_control:
    loop_var: ssh_cred

This is removing + sign which in the private key. also if you read the key from any variable, it is adding 'u[ private key]'
am i doing anything wrong ?

@sergeypapyan
Copy link

@gogskrish You should urlencode the key contents

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

8 participants