how to get jenkins Configure and security setting through an API

31 Views Asked by At

need to develop a Python script that displays all the settings of Jenkin results: Authentication type : # Matirx strategy List of all the setting values json or xml example code: import requests`your text`

Jenkins API URL

jenkins_url = 'http://your-jenkins-url/api/json'

Jenkins API request to get configuration information

response = requests.get(jenkins_url, auth=('your_username', 'your_api_token'))

Check if the request was successful (status code 200)

if response.status_code == 200: # Parse the JSON response jenkins_data = response.json()

# Access the 'authorizationStrategy' from the global security configuration
global_security_config = jenkins_data.get('globalSecurityConfig', {})
authorization_strategy = global_security_config.get('authorizationStrategy', '')

# Print the result
print('Authorization Strategy:', authorization_strategy)

else: # Print an error message if the request was not successful print('Failed to retrieve Jenkins configuration. Status Code:', response.status_code)

0

There are 0 best solutions below