Change the Jenkins URL that Kubernetes cloud agents connect to

Article ID:360031146292
2 minute readKnowledge base

Issue

  • I want to change the URL that kubernetes agents are using to connect to Jenkins

Resolution

The Kubernetes Plugin passes the Jenkins URL to the jnlp container in agent pods as an environment variable and the agent process connects to Jenkins using the script: https://github.com/jenkinsci/docker-inbound-agent/blob/master/jenkins-agent.

By default, the Jenkins URL configured under manage Manage Jenkins  Configure System  Jenkins Location is used. In most cases, this is acceptable. But in some cases it is required that agents connect to a different endpoint, for example to connect through a specific proxy load balancer or via internal IP / hostnames.

Kubernetes Plugin >= 1.28.4

The Kubernetes Plugin resolves the Jenkins URL from different sources in that order:

  1. The "Jenkins URL" configured for the Kubernetes Cloud under Manage Jenkins  Manage Nodes and Clouds  Configure Clouds

  2. Otherwise if NOT using WebSocket AND no credentials provided:

    • the value of the System Property KUBERNETES_JENKINS_URL (i.e. passing -DKUBERNETES_JENKINS_URL to the Jenkins startup arguments)

    • Otherwise, the value of the Environment Variable KUBERNETES_JENKINS_URL

  3. If empty or not specified, the "Jenkins URL" configured under Manage Jenkins  Configure System  Jenkins Location

See this method for more details.

Kubernetes Plugin < 1.28.4

The Kubernetes Plugin resolves the Jenkins URL from different sources in that order:

  1. The "Jenkins URL" configured for the Kubernetes Cloud under Manage Jenkins  Manage Nodes and Clouds  Configure Clouds

  2. If empty or not specified, the value of the System Property KUBERNETES_JENKINS_URL (i.e. passing -DKUBERNETES_JENKINS_URL to the Jenkins’s startup)

  3. If empty or not specified, the value of the Environment Variable KUBERNETES_JENKINS_URL

  4. If empty or not specified, the "Jenkins URL" configured under Manage Jenkins  Configure System  Jenkins Location