Skip to content

Commit 4c49aab

Browse files
committed
fix(k8s): do not overwrite cloud serverUrl with k3s when JENKINS_K8S_API_URL unset
ensureK8sCloud() was always setting serverUrl to JENKINS_K8S_API_URL ?: 'https://k3s:6443', which overwrote startup-configured URLs and caused UnknownHostException: k3s in GHA/shared Jenkins where 'k3s' does not resolve. Only set serverUrl (and jenkinsUrl/jenkinsTunnel) when the corresponding env vars are set; otherwise preserve existing cloud configuration. Signed-off-by: Daniel Pressler <danielpr@nvidia.com>
1 parent c94bb8d commit 4c49aab

File tree

1 file changed

+20
-3
lines changed

1 file changed

+20
-3
lines changed

src/com/mellanox/cicd/Matrix.groovy

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -873,11 +873,28 @@ def ensureK8sCloud(cloudName, namespace = "default") {
873873
j.clouds.add(cloud)
874874
}
875875

876-
cloud.serverUrl = System.getenv("JENKINS_K8S_API_URL") ?: "https://k3s:6443"
876+
// Only set serverUrl when JENKINS_K8S_API_URL is set; otherwise preserve existing (e.g. from
877+
// startup script). Do not default to "https://k3s:6443" here—that hostname only resolves in
878+
// local Docker; on shared Jenkins it causes UnknownHostException. Local runs must pass
879+
// JENKINS_K8S_API_URL (e.g. scripts/local_gha_ci.sh does).
880+
def apiUrl = System.getenv("JENKINS_K8S_API_URL")?.trim()
881+
if (apiUrl) {
882+
cloud.serverUrl = apiUrl
883+
}
877884
cloud.skipTlsVerify = true
878885
cloud.namespace = namespace ?: "default"
879-
cloud.jenkinsUrl = System.getenv("JENKINS_URL") ?: "http://jenkins:8080"
880-
cloud.jenkinsTunnel = System.getenv("JENKINS_TUNNEL") ?: "jenkins:50000"
886+
def jenkinsUrlEnv = System.getenv("JENKINS_URL")?.trim()
887+
if (jenkinsUrlEnv) {
888+
cloud.jenkinsUrl = jenkinsUrlEnv
889+
} else if (!cloud.jenkinsUrl) {
890+
cloud.jenkinsUrl = "http://jenkins:8080"
891+
}
892+
def tunnelEnv = System.getenv("JENKINS_TUNNEL")?.trim()
893+
if (tunnelEnv) {
894+
cloud.jenkinsTunnel = tunnelEnv
895+
} else if (!cloud.jenkinsTunnel) {
896+
cloud.jenkinsTunnel = "jenkins:50000"
897+
}
881898
if ((System.getenv("JENKINS_K8S_TOKEN") ?: "").trim()) {
882899
cloud.credentialsId = "k8s-sa-token"
883900
}

0 commit comments

Comments
 (0)