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

Document how to use shared library's global classes in Declarative

XMLWordPrintable

      Given the following file in a shared library's vars folder

      class acme implements Serializable {
          
          def script
          
          acme(script) {this.script = script}
      }
      

      And the following snippet of Declarative code

      stages {
              stage("Checking component sources and building snapshot") {
                  steps {
                      script {
                          acme = new acme(this)
                      }
                   }
                 }
      }
      

      The end result is an error like

      Unable to resolve class acme
      

      To make this work I need to move the acme initialization out of the pipeline block like this

      def acme = new acme(this)
      
      pipeline {
       .......
      

      Although that is good to me as now the acme instance is available to all stages the current documentation does not mention anything related to this and I believe is worthwhile to add this case to the documentation.

            Unassigned Unassigned
            rarabaolaza Raul Arabaolaza
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated: