• Icon: Improvement Improvement
    • Resolution: Won't Fix
    • Icon: Minor Minor
    • pipeline
    • None
    • Jenkins: 1.625.3
      Workflow plugin: 1.11

      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.

          [JENKINS-32400] Import shared Groovy code

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

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

              Created:
              Updated:
              Resolved: