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

Provide certain config variables to declarative pipelines

    • Icon: Improvement Improvement
    • Resolution: Unresolved
    • Icon: Minor Minor
    • workflow-cps-plugin
    • None
    • n/a

      We're using declarative piplelines for a number of build and test jobs, and all our systems are behind a proxy; depending on the DMZ the Jenkins instance is in, there are different proxy settings necessary.

      We'd like to access the Jenkins proxy settings as variables when running Groovy or shell scripts. Right now, this has to be added through a script {} block; we'd like the Pipeline plugin to provide these settings as standard variables in the default scope.

      This is a snippet of the code we're using right now:

      pipeline {
        agent any
        stages {
          stage('Preparation') {
          steps {
            script {
              def p = jenkins.model.Jenkins.getInstance().proxy
              env['http_proxy'] = "http://${p.name}:${p.port}"
              env['https_proxy'] = env['http_proxy']
              env['no_proxy'] = p.noProxyHost
            }
          }
        }
        stage('Build') {
          steps {
            sh 'docker build -t mms_builder_dockerrpm --build-arg http_proxy="${http_proxy}" --build-arg https_proxy="${https_proxy}" --build-arg no_proxy="${no_proxy}" .'
          }
        }
      }
      

      Ideally, we could simply access the ProxyConfig variables as Groovy or environment variables, or both.

          [JENKINS-46113] Provide certain config variables to declarative pipelines

          Andrew Bayer added a comment -

          I'd say this is a more general matter than just Declarative - you're looking to get more information added to the environment available throughout the Pipeline. I'd prefer to address that across all of Pipeline, not just Declarative.

          Andrew Bayer added a comment - I'd say this is a more general matter than just Declarative - you're looking to get more information added to the environment available throughout the Pipeline. I'd prefer to address that across all of Pipeline, not just Declarative.

          Ran into this today too, as /etc/profile and /etc/bash.bashrc files do not count for any shell or checkout.
          While the Jenkins Plugins may have the correct proxy set you'll still have to repeat yourself to configure this in your job or as global environment variables.
          I wondered why the proxy setting is not applied to everything (and every build) jenkins does?

          Daniel Geißler added a comment - Ran into this today too, as /etc/profile and /etc/bash.bashrc files do not count for any shell or checkout. While the Jenkins Plugins may have the correct proxy set you'll still have to repeat yourself to configure this in your job or as global environment variables. I wondered why the proxy setting is not applied to everything (and every build) jenkins does?

            Unassigned Unassigned
            stefanbethke Stefan Bethke
            Votes:
            2 Vote for this issue
            Watchers:
            5 Start watching this issue

              Created:
              Updated: