Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support overwriting baseurl in job names please #799

Open
xenuser opened this issue Nov 13, 2020 · 0 comments
Open

Support overwriting baseurl in job names please #799

xenuser opened this issue Nov 13, 2020 · 0 comments

Comments

@xenuser
Copy link

xenuser commented Nov 13, 2020

ISSUE TYPE
  • Feature Idea
Jenkinsapi VERSION

master from 13th November 2020

Jenkins VERSION

2.197

SUMMARY

I run a monitoring system with a self-written Python script which shall monitor Jenkins (e.g. number ob Jobs, number of running builds..). The monitoring script uses the Python module jenkinsapi.
We use Python 2.7 (I know, I know...).

When our monitoring container starts to monitor Jenkins, it makes use of Python and the awesome jenkinsapi module.
The check uses the following host url: http://jenkins:8080
This works, because Docker Swarm runs its own internal DNS and provides an A record, pointing to the IP of the running contianer (of Jenkins).

Now our monitoring system connects to http://jenkins:8080 and is able to receive a list of jobs:

for job_name, job_object in server.items():

server is Jenkins(jenkins_url)

Logging says:

DEBUG:urllib3.connectionpool:http://jenkins:8080 "GET /api/python?tree=jobs%5Bname%2Ccolor%2Curl%5D HTTP/1.1" 200 1524

Until here, everything is fine.
However, server.items() does not only receive a list of Jobs from Jenkins, it also iterates though all Jobs found in the first call.
And all the job names include the configured Jenkins baseurl, e.g.:

https://jenkins-stage.docker.company.com/job/Application-Docu/api/python

So what happens next? Instead of connecting to the given Jenkins host, the jenkinsapi will query Job details via the baseurl which is contained in the job name.

This works in many cases, but is opening up a second way of connecting.
While query one (get list of jobs) was connecting to jenkins:8080, query 2 (get details for every job) is connecting against https://official URL and suddenly needs cert handling and auth credentials.

I don't think that this behavior is consistent.

EXPECTED RESULTS

I expect the jenkinsapi module to work within a container environment or within service discovery environments, where one would have a different URL for connecting to Jenkins than the configured baseurl in Jenkins. This should be a normal use case for many users.

I would like to suggest to implement an optional feature which allows overwriting the baseurl (and protocol and port), no matter what's in the job name.

ACTUAL RESULTS

jenkinsapi runs the first connection via provided_baseurl, all further calls to query for job details use the baseurl from the job names.

USEFUL INFORMATION

This is how I modified the lib code and made it work for my use case. This is just an example, I guess one could solve it it better ways.

jobs.py from jenkinsapi module


def poll(self, tree='jobs[name,color,url]'):
        poll_dict = self.jenkins.poll(tree=tree) # new
        for job in poll_dict["jobs"]: # new
            job["url"] = job["url"].replace("https://jenkins-stage.docker.company.com", "http://jenkins:8080/") # new

        return poll_dict # new
        #return self.jenkins.poll(tree=tree) # old


Replacing/Rewriting the baseurl in the requester.py did not work for me since re-writing the port was not possible there.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant