Creation of Jenkins slaves and Credentials using the Remote Access API

3,128 views
Skip to first unread message

Kannan Manickam

unread,
Oct 29, 2013, 2:27:01 AM10/29/13
to jenkin...@googlegroups.com

Hello,

I am the author of the jenkins_api_client project: https://github.com/arangamani/jenkins_api_client

I used to be able to create a dump slave using some hack I had in http://www.arangamani.net/jenkins_api_client/JenkinsApi/Client/Node.html#create_dump_slave-instance_method which simply posts some JSON data to the “/computer/doCreateItem” endpoint and it used to work fine until we had the private key file as an option. Now that it got changed to use the new Credentials interface, it doesn’t work anymore. I can specify the credential ID in the JSON but I couldn’t get the credentials to work using the API.

After some hacking, I could get the credential to create using a POST of the following JSON data to “/credentials/configSumbit”

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
        }

But there doesn’t seem to be a way for me to obtain the ID of the created credential so I can’t automate this process.

Is there support for the new credentials interface in the Remote Access API? If not will this be added in the future?

Thanks,
Kannan.

Jesse Glick

unread,
Oct 29, 2013, 11:16:21 AM10/29/13
to jenkin...@googlegroups.com
On Tue, Oct 29, 2013 at 2:27 AM, Kannan Manickam <m...@arangamani.net> wrote:
> Is there support for the new credentials interface in the Remote Access API?
> If not will this be added in the future?

Sounds like a pull request is needed for credentials-plugin to offer a
nice REST interface.

Kannan Manickam

unread,
Oct 29, 2013, 4:44:19 PM10/29/13
to jenkinsci-dev@googlegroups.com com
Sure, I might have some time for making contribution to that. Are there some documents/code for making a new REST interface that I could use as a reference?
> --
> You received this message because you are subscribed to the Google Groups "Jenkins Developers" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to jenkinsci-de...@googlegroups.com.
> For more options, visit https://groups.google.com/groups/opt_out.

Jesse Glick

unread,
Oct 29, 2013, 5:14:20 PM10/29/13
to jenkin...@googlegroups.com
On Tue, Oct 29, 2013 at 4:44 PM, Kannan Manickam <m...@arangamani.net> wrote:
> Are there some documents/code for making a new REST interface that I could use as a reference?

https://wiki.jenkins-ci.org/display/JENKINS/Remote+access+API
https://wiki.jenkins-ci.org/display/JENKINS/Exposing+data+to+the+remote+API
https://wiki.jenkins-ci.org/display/JENKINS/Web+Method
https://wiki.jenkins-ci.org/display/JENKINS/Figuring+out+URL+binding+of+Stapler
http://stapler.kohsuke.org/reference.html

should get you started. And of course look for code examples in mature
and well-maintained components.

Kannan Manickam

unread,
Oct 29, 2013, 5:43:50 PM10/29/13
to jenkinsci-dev@googlegroups.com com
Awesome. Thanks Jesse.

Benny Daon

unread,
Jan 16, 2014, 3:45:15 AM1/16/14
to jenkin...@googlegroups.com
I just ran into the same issue working on the python jenkinsapi project. Any progress on making the credentials accessible from the RESTful API ?

Thanks,

Benny

wulo...@huawei.com

unread,
Dec 28, 2014, 9:01:00 PM12/28/14
to jenkin...@googlegroups.com
Hi, I tried the method you said, 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)

Could you give me the example?

Michael Sander

unread,
Dec 30, 2015, 8:30:49 AM12/30/15
to Jenkins Developers
After some playing around, the following curl command worked for me. Per


curl -XPOST 'localhost:8080/credential-store/domain/_/createCredentials' \
   
--data-urlencode 'json={
        "": "0",
        "credentials": {
            "scope": "GLOBAL",
            "id": "",
            "username": "foo",
            "password": "bar",
            "description": "biz",
            "$class": "com.cloudbees.plugins.credentials.impl.UsernamePasswordCredentialsImpl"
        }
    }'

Jesse Glick

unread,
Jan 5, 2016, 11:20:37 AM1/5/16
to Jenkins Dev

Rajender Venkatpur

unread,
Mar 8, 2018, 3:58:40 AM3/8/18
to Jenkins Developers
Below snippet worked for me 


--user userid:token
--data-urlencode 'json={
  "": "0",
  "credentials": {
    "scope": "GLOBAL",
    "id": "user name",
    "username": "jenkinsUserID",
    "password": "passwordToken",
    "description": "Short decription of user",
    "$class": "com.cloudbees.plugins.credentials.impl.UsernamePasswordCredentialsImpl"



Thank you
Rajender
Reply all
Reply to author
Forward
0 new messages