Create credentials on Jenkins UI

12 views
Skip to first unread message

Adharsha sri

unread,
Apr 26, 2022, 4:12:01 AM4/26/22
to jenkins...@googlegroups.com
We are trying to automate the process of creating credentails on Jenkins UI. We are using below script.
 While running the script getting 200 as response code but the credentails are not added/saved on jenkins UI. Can you please help us in this.


credentails.xml

<com.cloudbees.plugins.credentials.impl.UsernamePasswordCredentialsImpl>
  <scope>GLOBAL</scope>
  <id>deploy-key</id>
  <description>This is an example from REST API</description>
  <username>wecoyote</username>
  <password>secret123</password>
</com.cloudbees.plugins.credentials.impl.UsernamePasswordCredentialsImpl>


test.py

import requests
from requests.auth import HTTPBasicAuth
head = {'Content-Type': 'application/xml'}

jenkins_crumb_api = "https://username:token@jenkins_server/crumbIssuer/api/json"
response = requests.get(jenkins_crumb_api)
if (response.status_code == 200):
    print(response.status_code)
    head['Jenkins-Crumb'] = response.json()["crumb"]

head = {'Content-Type': 'application/xml'}
response = requests.post("https://jenkins_server/credentails/store/system/domain/domain_name/newCredentails",
                         auth=HTTPBasicAuth('username', 'token'),
                         headers=head, data= "credentails.xml")
print(response.status_code)

Jenkins version: 2.319.3.



Reply all
Reply to author
Forward
0 new messages