title: Global Variables in Jenkins Shared libraries
body: <p>I have a Jenkinsfile which uses a shared library. I would like to make a global variable which is usable in all functions of the shared library, similar to the <a href="https://jenkins.io/doc/book/pipeline/syntax/#parameters" rel="nofollow noreferrer"><code>params</code></a> object. However I always end up with</p>
  
  <pre><code>groovy.lang.MissingPropertyException: No such property: pipelineParams for class: groovy.lang.Binding
  </code></pre>
  
  <p>Following <a href="https://jenkins.io/doc/book/pipeline/shared-libraries/#defining-global-variables" rel="nofollow noreferrer">this guideline</a>, I define a <code>Field</code> in the <code>Jenkinsfile</code>:</p>
  
  <pre><code>import org.apache.commons.io.FileUtils
  @groovy.transform.Field
  def pipelineParams
  
  library identifier: 'pipeline-helper@master', retriever: modernSCM(
    [$class: 'GitSCMSource',
         remote: 'https://bitbucket/scm/jenkins/pipeline-helper.git',
         credentialsId: 'bitbucket.service.user'
    ])
  
  defaultCiPipelineMSBuild {
      nodes     = 'TEST-NODES' /* label of jenkins nodes*/
      email     = 'example@example.com' /* group mail for notifications */
      msbuild   = 'MSBUILD-DOTNET-4.6' /* ms build tool to use */ 
  }
  </code></pre>
  
  <p>And then in the <code>defaultCiPipelineMSBuild</code> I set the <code>pipelineParams</code></p>
  
  <pre><code>def call(body) {
      // evaluate the body block, and collect configuration into the object
      pipelineParams= [:]
      body.resolveStrategy = Closure.DELEGATE_FIRST
      body.delegate = pipelineParams
      body()
  
      pipeline {
      ...
  </code></pre>
  
  <p>Later on I call a function <code>buildApplication</code> which want's to consume the variable:</p>
  
  <pre><code>def msBuildExe = tool pipelineParams.msbuild
  </code></pre>