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.
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?
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"
}
}'