0

In Jenkins, we want to get the Pipeline stages information through API, e.g. a stage is success or fail. From another answer it seems we can achieve it through Pipeline REST API Plugin.

My question is:

Can Jenkinsapi and Python-Jenkins achieve the same thing? It seems they're designed for bare metal Jenkins, instead of the Pipeline plugin, right ? If that's the case, do we have similar Python library for Pipeline plugin?

Thanks!

mCY
  • 2,731
  • 7
  • 25
  • 43

2 Answers2

0

You have all the info to answer your own question in the documentation you linked. Just to put it together:

  • Jenkins has a REST API
  • The pipeline REST API plugin injects new endpoints in the Jenkins REST API to give you access to several pipeline info
  • Python-Jenkins and jenkinsapi you mentioned above are both wrappers around the Jenkins REST API to help you develop scripts/apps targeting the Jenkins API in Python. Since those modules/libs are based most probably based on the core API specification, they most probably don't provide specific methods to target the pipeline endpoints (but you can probably extend that quite easily).
Zeitounator
  • 38,476
  • 7
  • 53
  • 66
0

If you want to stay in Jenkinsapi, get_data() defined in JenkinsBase class could be used for querying Pipeline REST API directly. Not very sure if it's recommended or not.

Following codes works for me.

from jenkinsapi.jenkins import Jenkins
import requests
requests.packages.urllib3.disable_warnings()

# GET /job/:job-name/:run-id/wfapi/describe
url = 'https://localhost/job/anyjob/10/wfapi/describe'
jenkins = Jenkins(
    'https://localhost',
    username='username', 
    password='api_token', 
    ssl_verify=False, 
    lazy=True)
print(jenkins.get_data(url))
mCY
  • 2,731
  • 7
  • 25
  • 43