4

So far, I'm using the credentials plugin on Jenkins and I do a POST to {JENKINS_URL}/credentials/store/system/domain/_/createCredentials using a credentials.xml that looks like this:

<com.cloudbees.plugins.credentials.impl.UsernamePasswordCredentialsImpl>
            <scope>GLOBAL</scope>
            <id>my-test-cred</id>
            <description>This is an example from REST API</description>
            <username>xyz-test</username>
            <password>
              xyz-yay
            </password></com.cloudbees.plugins.credentials.impl.UsernamePasswordCredentialsImpl>

and it successfully creates a credential of type username:password.

But suppose I want to create a credential of type secret-text which would hold a token or a secret, like say, a GitHub token, how can I make a credentials.xml for that kind? I've searched high and low and I cannot find a definitive guide here :-(

Saturnian
  • 1,686
  • 6
  • 39
  • 65

2 Answers2

2

I used successfully the class from @rkparmar's proposal with XML format to create a secret text credential in Jenkins.

<org.jenkinsci.plugins.plaincredentials.impl.StringCredentialsImpl> 
   <scope>GLOBAL</scope>                                                                                          
   <id>testID</id> 
   <secret>thisIsAtest</secret> 
   <description>TEST</description> 
</org.jenkinsci.plugins.plaincredentials.impl.StringCredentialsImpl>
ouflak
  • 2,458
  • 10
  • 44
  • 49
koenig91
  • 21
  • 3
0

Agree! It is difficult to find xml to credential for secret-text. If you have way to get xml from .json than please find .json below to create credentials for secret-text

curl -X POST 'http://user:token@jenkins_server:8080/credentials/store/system/domain/_/createCredentials' \
--data-urlencode 'json={
  "": "0",
   "credentials": { 
   "scope": "GLOBAL", 
   "id": "myid", 
   "secret": "mysecret", 
   "description": "mydescription", 
   "$class": "org.jenkinsci.plugins.plaincredentials.impl.StringCredentialsImpl" 
  } 
}
rkparmar
  • 142
  • 5