Users
Users
Search for a user
- users.Users.search()
Search for a user by username.
- Parameters:
username (str) – The username of the user to search for.
- Returns:
User object corresponding to the username.
- Return type:
- Raises:
JenkinsGeneralException – If a general exception occurs.
from jenkins_pysdk.jenkins import Jenkins
jenkins = Jenkins(host="JenkinsDNS", username="admin", token="11e8e294cee85ee88b60d99328284d7608")
print(jenkins.users.search("test"))
The above code will output:
<jenkins_pysdk.users.User object at 0x000001BEEBF3CD30>
Get total users
- users.Users.total()
Get the total number of users.
- Returns:
Total number of users.
- Return type:
from jenkins_pysdk.jenkins import Jenkins
jenkins = Jenkins(host="JenkinsDNS", username="admin", token="11e8e294cee85ee88b60d99328284d7608")
print(jenkins.users.search("test"))
The above code will output:
3
Iterate all users
- users.Users.iter()
Iterate over all users.
- Returns:
Generator yielding User objects.
- Return type:
Generator[
jenkins_pysdk.usersUser]
from jenkins_pysdk.jenkins import Jenkins
jenkins = Jenkins(host="JenkinsDNS", username="admin", token="11e8e294cee85ee88b60d99328284d7608")
for user in jenkins.users.iter():
print(user.name)
The above code will output:
admin
new
test
List all users
- users.Users.list()
Get a list of all users.
- Returns:
List of User objects.
- Return type:
List[
jenkins_pysdk.users.User]
from jenkins_pysdk.jenkins import Jenkins
jenkins = Jenkins(host="JenkinsDNS", username="admin", token="11e8e294cee85ee88b60d99328284d7608")
print(jenkins.users.list())
The above code will output:
[<jenkins_pysdk.users.User object at 0x00000207B731CE50>, <jenkins_pysdk.users.User object at 0x00000207B73DD210>, <jenkins_pysdk.users.User object at 0x00000207B73DD960>]
Create a new user (as admin)
- users.Users.create()
Create a new user.
- Parameters:
config (
jenkins_pysdk.builders.Builder) – The user to be created.- Returns:
An object representing the action performed in Jenkins.
- Return type:
from jenkins_pysdk.jenkins import Jenkins
from jenkins_pysdk.builders import Builder
jenkins = Jenkins(host="JenkinsDNS", username="admin", token="11e8e294cee85ee88b60d99328284d7608")
new_user = Builder.User(username="my_new_user", password="my_new_pass", fullname="jamesJ", email="jamesj@j.com")
print(jenkins.users.create(new_user)
The above code will output:
request=<HTTPSessionRequestObject object at 1868709648224> content='[200] Successfully created user (my_new_user).' status_code=200
User
Get the user name
from jenkins_pysdk.jenkins import Jenkins
jenkins = Jenkins(host="JenkinsDNS", username="admin", token="11e8e294cee85ee88b60d99328284d7608")
user = jenkins.users.search("test")
print(user.name)
The above code will output:
test
Get the user URL
from jenkins_pysdk.jenkins import Jenkins
jenkins = Jenkins(host="JenkinsDNS", username="admin", token="11e8e294cee85ee88b60d99328284d7608")
user = jenkins.users.search("test")
print(user.url)
The above code will output:
https://JenkinsDNS/user/test
Get the user description
- users.User.description()
Get the description of the user.
- Returns:
The description of the user.
- Return type:
from jenkins_pysdk.jenkins import Jenkins
jenkins = Jenkins(host="JenkinsDNS", username="admin", token="11e8e294cee85ee88b60d99328284d7608")
user = jenkins.users.search("test")
print(user.description)
The above code will output:
This user is using for testing automation.
Get the user’s credentials
- users.User.credentials()
Search the users’ personal credential safe.
- Parameters:
domain (str, optional) – The domain to search for credentials (default is “_”).
- Returns:
A domain object representing the user’s personal credential safe.
- Return type:
- Raises:
JenkinsNotFound: If the users credentials were not found.
from jenkins_pysdk.jenkins import Jenkins
jenkins = Jenkins(host="JenkinsDNS", username="admin", token="11e8e294cee85ee88b60d99328284d7608")
user = jenkins.users.search("admin")
print([cred.id for cred in user.credentials(domain="my_creds_store").list()])
The above code will output:
['my_pypi_password']
Get the user’s views
- users.User.views()
Get a list of views associated with the user.
- Returns:
A list of view objects associated with the user.
- Return type:
List[jenkins_pysdk.views.View]
- Raises:
JenkinsGeneralException – If a general exception occurs.
from jenkins_pysdk.jenkins import Jenkins
jenkins = Jenkins(host="JenkinsDNS", username="admin", token="11e8e294cee85ee88b60d99328284d7608")
user = jenkins.users.search("test")
print(user.views)
The above code will output:
[<jenkins_pysdk.views.View object at 0x000002AF1883DDB0>, <jenkins_pysdk.views.View object at 0x000002AF1883CCD0>, <jenkins_pysdk.views.View object at 0x000002AF1883C6A0>, <jenkins_pysdk.views.View object at 0x000002AF1883C8B0>, <jenkins_pysdk.views.View object at 0x000002AF1883D0C0>]
Get the user’s builds
- users.User.builds()
Get a list of builds associated with the user.
- Returns:
A list of build objects associated with the user.
- Return type:
- Raises:
JenkinsGeneralException – If a general exception occurs.
from jenkins_pysdk.jenkins import Jenkins
jenkins = Jenkins(host="JenkinsDNS", username="admin", token="11e8e294cee85ee88b60d99328284d7608")
user = jenkins.users.search("admin")
print(user.builds)
The above code will output:
<HTML Output>
Delete the user
- users.User.delete()
Delete the user.
- Returns:
Action object representing the result of the deletion operation.
- Return type:
from jenkins_pysdk.jenkins import Jenkins
jenkins = Jenkins(host="JenkinsDNS", username="admin", token="11e8e294cee85ee88b60d99328284d7608")
user = jenkins.users.search("test")
print(user.delete())
The above code will output:
request=<Request object at 2813768495920> content='[400] Failed to delete user (test).' status_code=200
Terminate a users’ sessions
- users.User.logout()
Terminate the user’s session.
- Returns:
Result of the logout request
- Return type:
from jenkins_pysdk.jenkins import Jenkins
jenkins = Jenkins(host="JenkinsDNS", username="admin", token="11e8e294cee85ee88b60d99328284d7608")
user = jenkins.users.search("test")
print(user.logout())
The above code will output:
request=<Request object at 2073057402192> content='[200] Successfully logged out.' status_code=200
Me
Get my username
from jenkins_pysdk.jenkins import Jenkins
jenkins = Jenkins(host="JenkinsDNS", username="admin", token="11e8e294cee85ee88b60d99328284d7608")
print(jenkins.me.name)
The above code will output:
admin
Get my user URL
from jenkins_pysdk.jenkins import Jenkins
jenkins = Jenkins(host="JenkinsDNS", username="admin", token="11e8e294cee85ee88b60d99328284d7608")
print(jenkins.me.url)
The above code will output:
https://JenkinsDNS/me
Get my user description
- users.User.description()
Get the description of the user.
- Returns:
The description of the user.
- Return type:
from jenkins_pysdk.jenkins import Jenkins
jenkins = Jenkins(host="JenkinsDNS", username="admin", token="11e8e294cee85ee88b60d99328284d7608")
print(jenkins.me.description)
The above code will output:
None
Get my user credentials
- users.User.credentials()
Search the users’ personal credential safe.
- Parameters:
domain (str, optional) – The domain to search for credentials (default is “_”).
- Returns:
A domain object representing the user’s personal credential safe.
- Return type:
- Raises:
JenkinsNotFound: If the users credentials were not found.
from jenkins_pysdk.jenkins import Jenkins
jenkins = Jenkins(host="JenkinsDNS", username="admin", token="11e8e294cee85ee88b60d99328284d7608")
print([passw.id for passw in jenkins.me.credentials(domain="admin_domain").list()])
The above code will output:
['my_pypi_password']
Get my user views
- users.User.views()
Get a list of views associated with the user.
- Returns:
A list of view objects associated with the user.
- Return type:
List[jenkins_pysdk.views.View]
- Raises:
JenkinsGeneralException – If a general exception occurs.
from jenkins_pysdk.jenkins import Jenkins
jenkins = Jenkins(host="JenkinsDNS", username="admin", token="11e8e294cee85ee88b60d99328284d7608")
print([view.name for view in jenkins.me.views])
The above code will output:
['builder_1', 'builder_2', 'builder_4', 'builder_d', 'builder_e', 'builder_folder', 'builder_w', 'folder1', 'folder3', 'my_new_folder_name', 'new_folder', 'new_freestyle']
Get my user builds
- users.User.builds()
Get a list of builds associated with the user.
- Returns:
A list of build objects associated with the user.
- Return type:
- Raises:
JenkinsGeneralException – If a general exception occurs.
from jenkins_pysdk.jenkins import Jenkins
jenkins = Jenkins(host="JenkinsDNS", username="admin", token="11e8e294cee85ee88b60d99328284d7608")
print(jenkins.me.builds)
The above code will output:
<HTML Output>
Terminate my session
- users.User.logout()
Terminate the user’s session.
- Returns:
Result of the logout request
- Return type:
from jenkins_pysdk.jenkins import Jenkins
jenkins = Jenkins(host="JenkinsDNS", username="admin", token="11e8e294cee85ee88b60d99328284d7608")
print(jenkins.me.logout())
The above code will output:
request=<Request object at 2012346268496> content='[200] Successfully logged out.' status_code=200