Queues
Queue
Iterate all queue items
- queues.Queue.iter()
Iterates over the items in the Jenkins queue.
- Parameters:
_paginate (int) – The number of items to fetch per page (default is 0, meaning all items).
- Returns:
A generator yielding QueueItem objects representing items in the queue.
- Return type:
Generator[
jenkins_pysdk.queues.QueueItem]- Raises:
JenkinsGeneralException – If a general exception occurs.
from jenkins_pysdk.jenkins import Jenkins
jenkins = Jenkins(host="JenkinsDNS", username="admin", token="11e8e294cee85ee88b60d99328284d7608")
for item in jenkins.queue.iter():
print(item.number, item.job.path)
The above code will output:
52 new_freestyle
54 folder1
List all queue items
- queues.Queue.list()
Lists items in the Jenkins queue.
- Parameters:
_paginate (int) – The number of items to fetch per page (default is 0, meaning all items).
- Returns:
A list of QueueItem objects representing items in the queue.
- Return type:
from jenkins_pysdk.jenkins import Jenkins
jenkins = Jenkins(host="JenkinsDNS", username="admin", token="11e8e294cee85ee88b60d99328284d7608")
print(jenkins.queue.list())
The above code will output:
[<jenkins_pysdk.queues.QueueItem object at 0x00000221F99323B0>, <jenkins_pysdk.queues.QueueItem object at 0x00000221F9932350>]
Get the newest item in the queue
- queues.Queue.newest()
Returns the newest item in the Jenkins queue.
- Returns:
The newest item in the Jenkins queue.
- Return type:
jenkins_pysdk.jenkins.QueueItem- Raises:
JenkinsEmptyQueue – If the queue is empty.
from jenkins_pysdk.jenkins import Jenkins
jenkins = Jenkins(host="JenkinsDNS", username="admin", token="11e8e294cee85ee88b60d99328284d7608")
newest = jenkins.queue.newest
print(newest.job.path, newest.number)
The above code will output:
new_freestyle 52
Get the oldest item in the queue
- queues.Queue.oldest()
Returns the oldest item in the Jenkins queue.
- Returns:
The oldest item in the Jenkins queue.
- Return type:
jenkins_pysdk.jenkins.QueueItem- Raises:
JenkinsEmptyQueue – If the queue is empty.
from jenkins_pysdk.jenkins import Jenkins
jenkins = Jenkins(host="JenkinsDNS", username="admin", token="11e8e294cee85ee88b60d99328284d7608")
oldest = jenkins.queue.oldest
print(oldest.job.path, oldest.number)
The above code will output:
folder1 54
Get total queue items
- queues.Queue.total()
Returns the total number of items in the Jenkins queue.
- Returns:
The total number of items in the Jenkins queue.
- Return type:
from jenkins_pysdk.jenkins import Jenkins
jenkins = Jenkins(host="JenkinsDNS", username="admin", token="11e8e294cee85ee88b60d99328284d7608")
print(jenkins.queue.total)
The above code will output:
1
QueueItem
Get the item queue ID
- queues.QueueItem.id()
Returns the ID of the queue item.
- Returns:
The ID of the queue item.
- Return type:
from jenkins_pysdk.jenkins import Jenkins
jenkins = Jenkins(host="JenkinsDNS", username="admin", token="11e8e294cee85ee88b60d99328284d7608")
print(jenkins.queue.oldest.id)
The above code will output:
56
Get the item build number
- queues.QueueItem.number()
Returns the Build number of the queue item.
- Returns:
The Build number of the queue item.
- Return type:
from jenkins_pysdk.jenkins import Jenkins
jenkins = Jenkins(host="JenkinsDNS", username="admin", token="11e8e294cee85ee88b60d99328284d7608")
print(jenkins.queue.oldest.number)
The above code will output:
50
Get the item scheduled time
- queues.QueueItem.scheduled()
Returns the timestamp when the queue item was scheduled.
- Returns:
The timestamp when the queue item was scheduled.
- Return type:
from jenkins_pysdk.jenkins import Jenkins
jenkins = Jenkins(host="JenkinsDNS", username="admin", token="11e8e294cee85ee88b60d99328284d7608")
print(jenkins.queue.oldest.scheduled)
The above code will output:
1713706848264
Get the item blocked status
- queues.QueueItem.blocked()
Indicates whether the queue item is blocked.
- Returns:
True if the queue item is blocked, False otherwise.
- Return type:
from jenkins_pysdk.jenkins import Jenkins
jenkins = Jenkins(host="JenkinsDNS", username="admin", token="11e8e294cee85ee88b60d99328284d7608")
print(jenkins.queue.oldest.blocked)
The above code will output:
True
Get the item stuck status
- queues.QueueItem.stuck()
Indicates whether the queue item is stuck.
- Returns:
True if the queue item is stuck, False otherwise.
- Return type:
from jenkins_pysdk.jenkins import Jenkins
jenkins = Jenkins(host="JenkinsDNS", username="admin", token="11e8e294cee85ee88b60d99328284d7608")
print(jenkins.queue.oldest.stuck)
The above code will output:
False
Get the item queue reason
- queues.QueueItem.reason()
Returns the reason for the queue item.
- Returns:
The reason for the queue item.
- Return type:
from jenkins_pysdk.jenkins import Jenkins
jenkins = Jenkins(host="JenkinsDNS", username="admin", token="11e8e294cee85ee88b60d99328284d7608")
print(jenkins.queue.oldest.reason)
The above code will output:
Build #49 is already in progress (ETA: 3 min 48 sec)
Get the item job type
- queues.QueueItem.type()
Returns the Job type of the queue item.
- Returns:
The Job type of the queue item.
- Return type:
from jenkins_pysdk.jenkins import Jenkins
jenkins = Jenkins(host="JenkinsDNS", username="admin", token="11e8e294cee85ee88b60d99328284d7608")
print(jenkins.queue.oldest.type)
The above code will output:
hudson.model.FreeStyleProject
Interact with the item Build
- queues.QueueItem.build()
Returns the build associated with the queue item.
- Returns:
The build associated with the queue item.
- Return type:
jenkins_pysdk.jenkins.Build
from jenkins_pysdk.jenkins import Jenkins
jenkins = Jenkins(host="JenkinsDNS", username="admin", token="11e8e294cee85ee88b60d99328284d7608")
print(jenkins.queue.oldest.build.console())
The above code will output:
http://JenkinsDNS/job/new_freestyle/50
Interact with the item Job
- queues.QueueItem.job()
Returns the job associated with the queue item.
- Returns:
The job associated with the queue item.
- Return type:
from jenkins_pysdk.jenkins import Jenkins
jenkins = Jenkins(host="JenkinsDNS", username="admin", token="11e8e294cee85ee88b60d99328284d7608")
print(jenkins.queue.oldest.job.delete())
The above code will output:
request=<Request object at 2191625717376> content='[204] Successfully deleted job.' status_code=204