When you submit a job using build_job() api it sends it to the queue where the job roughly waits around 5secs before being executed.
During this time if you execute get_queue_item(queue_id) you will see why: In the quiet period. Expires in 3.7 sec in the response. To get the build id of the job you just submitted you need to wait till the job gets out of the queue and that when the response for get_queue_item(queue_id) is updated with job details.
Sample code:
new_job = server.build_job('test-job') # returns queue id of the new build
while True:
queue_info = server.get_queue_item(new_job)
if queue_info['why'] is None:
print(f"The job url is {queue_info['executable']['url']}")
break
Sample response:
{
'_class': 'hudson.model.Queue$LeftItem',
'actions': [
{
'_class': 'hudson.model.CauseAction',
'causes': [
{
'_class': 'hudson.model.Cause$UserIdCause',
'shortDescription': 'Started by user ****',
'userId': '*****',
'userName': '****'
}
]
}
],
'blocked': False,
'buildable': False,
'id': 30,
'inQueueSince': 1708121493104,
'params': '',
'stuck': False,
'task': {
'_class': 'hudson.model.FreeStyleProject',
'name': 'test-job',
'url': 'http: //opense-jenki-*********/job/test-job/',
'color': 'blue_anime'
},
'url': 'queue/item/30/',
'why': None,
'cancelled': False,
'executable': {
'_class': 'hudson.model.FreeStyleBuild',
'number': 28,
'url': 'http://opense-jenki-**************/job/test-job/28/'
}
}