Uploaded image for project: 'Jenkins'
  1. Jenkins
  2. JENKINS-59632

Plugin does not respect the jenkinsUrl configuration from configuration-as-code

    • Icon: Bug Bug
    • Resolution: Unresolved
    • Icon: Major Major
    • kubernetes-plugin
    • None
    • Jenkins 2.176.3, plugin version 1.19.1

      It appears the the "Jenkins URL" configuration in the main configuration is not properly over-writable from the configuration as code plugin.

      The configuration snippet below is always overwritten at runtime, it seems, with whatever the Kubernetes master Service IP turns out to be. In the case of my local testing of our Jenkins master image, which is not running in Kubernetes, after booting with the configuration below the "Jenkins URL" setting is `http://:`

      ---
      jenkins:
        clouds:
        - kubernetes:
            connectTimeout: 5
            jenkinsUrl: "https://some-external-dns-entry/"
      
      

          [JENKINS-59632] Plugin does not respect the jenkinsUrl configuration from configuration-as-code

          R. Tyler Croy added a comment -

          I have a workaround which I am using for now, which relies on the init.groovy.d/ support in Jenkins:

          /*
           * This script helps work around an issue with the Jenkins Kubernetes plugin
           * which doesn't properly receive the configured `jenkinsUrl` on restart.
           *
           * The script is making an assumption that we can wait for a few seconds on
           * bootstrap before overwriting the URL on the object directly
           *
           * See: <https://issues.jenkins-ci.org/browse/JENKINS-59632>
           */
          import jenkins.model.*
          import org.csanchez.jenkins.plugins.kubernetes.*
          
          /*
           * Spinning off a separate thread to do this work so this doesn't block the
           * bootstrap of the Jenkins master
           */
          Thread.start {
              sleep 5000
              /*
               * On the off chance we have more clouds, this is looking for the
               * Kubernetes one only, and then setting the URL to what we have in our
               * environment defined as an override.
               */
              for (cloud in Jenkins.instance.clouds) {
                  if (cloud.class == KubernetesCloud) {
                      if (System.env.KUBERNETES_JENKINS_URL) {
                          println "Overwriting the Kubernetes Jenkisn URL to: ${System.env.KUBERNETES_JENKINS_URL}"
                          cloud.setJenkinsUrl(System.env.KUBERNETES_JENKINS_URL);
                          Jenkins.instance.save();
                      }
                  }
              }
          }
          

          R. Tyler Croy added a comment - I have a workaround which I am using for now, which relies on the init.groovy.d/ support in Jenkins: /* * This script helps work around an issue with the Jenkins Kubernetes plugin * which doesn't properly receive the configured `jenkinsUrl` on restart. * * The script is making an assumption that we can wait for a few seconds on * bootstrap before overwriting the URL on the object directly * * See: <https: //issues.jenkins-ci.org/browse/JENKINS-59632> */ import jenkins.model.* import org.csanchez.jenkins.plugins.kubernetes.* /* * Spinning off a separate thread to do this work so this doesn't block the * bootstrap of the Jenkins master */ Thread .start { sleep 5000 /* * On the off chance we have more clouds, this is looking for the * Kubernetes one only, and then setting the URL to what we have in our * environment defined as an override. */ for (cloud in Jenkins.instance.clouds) { if (cloud.class == KubernetesCloud) { if ( System .env.KUBERNETES_JENKINS_URL) { println "Overwriting the Kubernetes Jenkisn URL to: ${ System .env.KUBERNETES_JENKINS_URL}" cloud.setJenkinsUrl( System .env.KUBERNETES_JENKINS_URL); Jenkins.instance.save(); } } } }

            Unassigned Unassigned
            rtyler R. Tyler Croy
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated: