How to retrieve JENKINS_URL via script "outside" CI ? Or the hostname of the master ?

22 views
Skip to first unread message

Martin Jost

unread,
Feb 27, 2020, 1:21:07 PM2/27/20
to Jenkins Users
Hello,

our CI system is reachable under different names (by ssh port forwarders running on some machines - background/reason below).
So you can access the system as something like
and

Actually Jenkins is running e.g. on "system1".
Jenkins itself "knows" this, via the setting in "Jenkins Location" /
"Jenkins URL" in the configuration.
In a CI job, this is visible via the shell variable JENKINS_URL.
All fine and nice.

Now I can get the list of nodes in CI using
/usr/bin/wget  --auth-no-challenge --no-proxy "http://system1.domain:9999//computer/api/xml?xpath=*/computer/displayName&wrapper=foo" -O "/tmp/Ymy2V19UpB"
"Unfortunately" for the master, this just returns "master".

So, how can I retrieve the hostname of the master ? (When the call is not done in a CI job - I need this for administration from "outside")
I either seem to need JENKINS_URL or a way to get the full hostname of the master.
Because of the port forwarder, a script doesn't know if Jenkins is running on 'system1' or 'system2', so the URL used in "wget" above, doesn't help.

How can I get that ?
I've searched the Web, the REST API and the CLI-interface (using jenkins-cli.jar) in vain.

Regards

Martin

We use this approach, because we swap the physical machine on Jenkins core updates, to keep the old state for some time for a possibly needed fallback.
To the users we "hide" this via the port forwarder, so they don't need the current physical name. This way URLs like e.g. on mails from CI stay valid.

Martin Jost

unread,
Feb 27, 2020, 1:42:04 PM2/27/20
to jenkins...@googlegroups.com
Ok, "as usual" I found something looking like part of the solution 5 Min later...

Discovering Jenkins on the network

Jenkins instances listen on UDP port 33848. Whenever a UDP packet is received, it will respond with a short XML fragment that shows the connection information. This XML has the following format:

<hudson>
  <version>1.380</version>             <!-- version of Jenkins -->
  <url>http://somewhere/jenkins/</url> <!-- HTTP URL. Not available if not configured -->
  <slave-port>12345</slave-port>       <!-- if TCP slave listener port is configured, its number -->
</hudson>

By using this, a client can use a UDP broadcast to try to discover nearby Jenkins instances. This is primarily useful for Swarm Plugin.


So I could check the list of potential hosts; the one answering is the right one.
But:
> nc -u system1.domain 33848
piep
Ncat: Connection refused.

Still not there ...

Martin

--
You received this message because you are subscribed to a topic in the Google Groups "Jenkins Users" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/jenkinsci-users/FvmbmFkofpc/unsubscribe.
To unsubscribe from this group and all its topics, send an email to jenkinsci-use...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/jenkinsci-users/96fb7ae8-81fc-43d7-9583-1f98558806fb%40googlegroups.com.
Reply all
Reply to author
Forward
0 new messages