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

Import shared Groovy code

    XMLWordPrintable

    Details

    • Type: Improvement
    • Status: Resolved (View Workflow)
    • Priority: Minor
    • Resolution: Won't Fix
    • Component/s: pipeline
    • Labels:
      None
    • Environment:
      Jenkins: 1.625.3
      Workflow plugin: 1.11
    • Similar Issues:

      Description

      It should be possible to import shared Groovy code from the SCM source in a Workflow job. For instance, if my workflow script (flow.groovy) needs to access variables from another script (constants.groovy) and they are both in the SCM repo that the Workflow job checked out, it should be simple to do. It's not and currently the unabashedly terrible workaround is to do this:

      def constants
      
      stage('Import dependencies')
      node{  
        git(url: 'ssh://git@mygitserver.com:7999/ex/workflow.git', credentialsId: '60cda0cc-f13d-448c-9947-28b926a20628')
        constants = load('constants.groovy')
      }
      

      This works, but the fact that another node has to be spun up and another git checkout command is required is awful. It should be pretty straightfoward to have Jenkins simply load one of these files. Something like this:

      constants = import("constants.groovy")
      

      I'm pretty sure Groovy won't let you use "import" since it's a resered keyword, but I don't have any particularly strong feelings about the semantics of this command. I just want a way to load these files easily.

        Attachments

          Issue Links

            Activity

            monitorjbl Taylor Jones created issue -
            jglick Jesse Glick made changes -
            Field Original Value New Value
            Link This issue is related to JENKINS-34596 [ JENKINS-34596 ]
            jglick Jesse Glick made changes -
            Link This issue depends on JENKINS-33273 [ JENKINS-33273 ]
            jglick Jesse Glick made changes -
            Link This issue is related to JENKINS-31155 [ JENKINS-31155 ]
            jglick Jesse Glick made changes -
            Epic Link JENKINS-35386 [ 171179 ]
            rtyler R. Tyler Croy made changes -
            Workflow JNJira [ 168022 ] JNJira + In-Review [ 182936 ]
            jglick Jesse Glick made changes -
            Resolution Won't Fix [ 2 ]
            Status Open [ 1 ] Resolved [ 5 ]
            abayer Andrew Bayer made changes -
            Component/s pipeline-general [ 21692 ]
            abayer Andrew Bayer made changes -
            Component/s workflow-plugin [ 18820 ]

              People

              Assignee:
              jglick Jesse Glick
              Reporter:
              monitorjbl Taylor Jones
              Votes:
              6 Vote for this issue
              Watchers:
              7 Start watching this issue

                Dates

                Created:
                Updated:
                Resolved: