How do I use the Jenkins CLI commands for Credentials Plugin?

7,111 views
Skip to first unread message

Vishwanath V

unread,
Aug 6, 2016, 3:32:22 AM8/6/16
to Jenkins Users
Hi all,

I need to automatedly load sets of credentials to a Jenkins instance, so that my jobs can pick up these credentials. 

For this purpose I am using the Jenkins CLI, specifically the set of commands provided by the Credentials Provider plugin:

  create-credentials-by-xml
    Create Credential by XML
  create-credentials-domain-by-xml
    Create Credentials Domain by XML
  get-credentials-as-xml
    Get a Credentials as XML (secrets redacted)
  get-credentials-domain-as-xml
    Get a Credentials Domain as XML
  list-credentials
    Lists the Credentials in a specific Store
  list-credentials-context-resolvers
    List Credentials Context Resolvers
  list-credentials-providers
    List Credentials Providers
   update-credentials-by-xml
    Update Credentials by XML
  update-credentials-domain-by-xml
    Update Credentials Domain by XML

I am trying to understand how to use them, but there is literally no documentation on this beyond the actual code (which I unfortunately am unable to understand). 

Question 1. What is the "Store ID"? 

Based on the error messages, I understand it is 
list-credentials [Store ID]

I am unable to understand what the Store ID is. Another error message says it should be in the format Provider::Resolver::ContextPath.
But where would I get this information from?

Question 2: How do I load an XML for "create-credentials-by-xml"?

When I use the create-credentials-by-xml, I assume I need to provide an XML file. How do I provide this ? i.e would it be as follows
create-credentials-by-xml [Store ID] [Path to XML]
??

Brandon R

unread,
Aug 15, 2016, 5:12:27 PM8/15/16
to Jenkins Users
I've been looking into this as well and made a little progress by digging around https://github.com/jenkinsci/credentials-plugin

For store, I used "system::system::jenkins" like in their tests.  For domain I tried variations on the word "global" but none worked.  I then tried underscore '_' as a wild guess and that worked.  I tried that because it's in the url when you hover on (global) on the credentials page.

Anyway, I haven't tried creating creds yet, but I can at least get them like:

java -jar /usr/share/jenkins/jenkins-cli.jar -s http://localhost:8080 -i ~jenkins/.ssh/id_rsa list-credentials system::system::jenkins

and

java -jar /usr/share/jenkins/jenkins-cli.jar -s http://localhost:8080 -i ~jenkins/.ssh/id_rsa get-credentials-as-xml system::system::jenkins _ somecredname

(note that I require auth hence the -i. This might not be relevant in your case)

Hope this helps some.

Andreas P

unread,
Sep 2, 2016, 10:22:43 AM9/2/16
to Jenkins Users
the way you load the XML is by pipeing it into the command. e.g.:
cat test.xml | java -jar jenkins-cli.jar -s http://localhost:9080/jenkins/ update-credentials-by-xml "SystemCredentialsProvider::SystemContextResolver::jenkins" "(global)" MYTEST

it would be nice if the documentation would give hints to that. (or I didnt find them)
Reply all
Reply to author
Forward
0 new messages