Safeer Pasha
Safeer Pasha

Reputation: 19

Python | Jenkins API | Unable to get build data or build response

Python Version - 3.10.4 and Jenkins Version - 2.321 Am trying to fetch the build information using python script and Jenkins API.

from jenkinsapi.jenkins import Jenkins

def get_server_instance():
    jenkins_url = 'My build URL/api/json?pretty=true'
    server = Jenkins(jenkins_url, username = 'my user id', password = 'My API token')
    return server

if __name__ == '__main__':
    print (get_server_instance().version)

"""Get job details of each job that is running on the Jenkins instance"""
def get_job_details():
    # Refer Example #1 for definition of function 'get_server_instance'
    server = get_server_instance()
    for j in server.get_jobs():
        job_instance = server.get_job(j[0])
        print ('Job Name:%s' %(job_instance.name))
        print ('Job Description:%s' %(job_instance.get_description()))
        print ('Is Job running:%s' %(job_instance.is_running()))
        print ('Is Job enabled:%s' %(job_instance.is_enabled()))

Script is returning only jenkins version not the build information as such and its not even giving any error to work further, Am confused here, how to get the build information and its artifact information.

Output:- 2.321

Any assistance or help will be appreciated.

Upvotes: 1

Views: 435

Answers (1)

Tiberius Soanea
Tiberius Soanea

Reputation: 11

You are not calling get_job_details in main.

Upvotes: 1

Related Questions