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

Provide certain config variables to declarative pipelines

XMLWordPrintable

    • 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.

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

              Created:
              Updated: