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

Allow plugins to contribute to Pipeline global library

      I'd like to be able to write a plugin that provides an opinionated DSL for Pipeline, behaving like it had been added to the global library, i.e., something like https://github.com/jenkinsci/workflow-examples/tree/master/global-library-examples/global-function but more so. I like the idea of delivering it via a plugin so that it can be tested, versioned, released, etc like any other plugin, but I don't see any way to do this currently. I'd imagine the logical way to do this would be to add the capacity to do this to Pipeline proper, but I could be wrong.

          [JENKINS-32731] Allow plugins to contribute to Pipeline global library

          Andrew Bayer created issue -

          Michael Neale added a comment -

          The only real problem I can forsee is that the names of DSL files in the global lib are, well, global.

          eg:

          builg.groovy is used as

          build {
          ..
          }

          In the script. If you install 2 plugins that each want to have a build.groovy - how is the conflict resolved? will the second one they install fail?
          (I fear to suggest qualified imports.... as that kind of harshes the vibe, but some way to resolve this may be warranted).

          Michael Neale added a comment - The only real problem I can forsee is that the names of DSL files in the global lib are, well, global. eg: builg.groovy is used as build { .. } In the script. If you install 2 plugins that each want to have a build.groovy - how is the conflict resolved? will the second one they install fail? (I fear to suggest qualified imports.... as that kind of harshes the vibe, but some way to resolve this may be warranted).

          Andrew Bayer added a comment -

          Good point. I'd probably lean towards qualified imports - we've already got a de facto requirement for uniqueness on plugin IDs, package/class names, etc, so there should be something we can reuse from that, first instinct being plugin IDs, so something like plugin "pipeline-my-dsl" providing the equivalent of "src/build.groovy" in the global library would be used as:

          pipeline-my-dsl.build { ... }
          

          Less elegant, but also safer, obviously. =)

          Andrew Bayer added a comment - Good point. I'd probably lean towards qualified imports - we've already got a de facto requirement for uniqueness on plugin IDs, package/class names, etc, so there should be something we can reuse from that, first instinct being plugin IDs, so something like plugin "pipeline-my-dsl" providing the equivalent of "src/build.groovy" in the global library would be used as: pipeline-my-dsl.build { ... } Less elegant, but also safer, obviously. =)

          Jesse Glick added a comment -

          Currently this is your option. Likely we will need a stronger API to support inclusion in DSLD/GDSL in the future.

          Jesse Glick added a comment - Currently this is your option. Likely we will need a stronger API to support inclusion in DSLD/GDSL in the future.
          Jesse Glick made changes -
          Labels New: api groovy

          Jesse Glick added a comment -

          Jesse Glick added a comment - Close try

          Michael Neale added a comment -

          Based on what I have seen, I think there is sufficient ability for plugins to add to a global library already - by providing a GlobalVariable extension. Some intelligence needs to be applied around naming and state, but overall, it works just fine (or can be sugared up). There is no need for plugins to "commit" to the workflowLibs repo - I think that would be not right.

          So I vote we close this in favour of an example/wiki page as "done".

          Michael Neale added a comment - Based on what I have seen, I think there is sufficient ability for plugins to add to a global library already - by providing a GlobalVariable extension. Some intelligence needs to be applied around naming and state, but overall, it works just fine (or can be sugared up). There is no need for plugins to "commit" to the workflowLibs repo - I think that would be not right. So I vote we close this in favour of an example/wiki page as "done".

          Jesse Glick added a comment -

          I think there is sufficient ability for plugins to add to a global library already - by providing a GlobalVariable extension

          …but we still need an API to allow DSLD/GDSL generators to know that a given variable has a type given by a specific Groovy resource, so they could have a chance at offering strong typing. For example, if docker-workflow is installed, you would ideally like IDEA to be able to complete docker.image('maven').ins to inside.

          Jesse Glick added a comment - I think there is sufficient ability for plugins to add to a global library already - by providing a GlobalVariable extension …but we still need an API to allow DSLD/GDSL generators to know that a given variable has a type given by a specific Groovy resource, so they could have a chance at offering strong typing. For example, if docker-workflow is installed, you would ideally like IDEA to be able to complete docker.image('maven').ins to inside .

          Andrew Bayer added a comment -

          +1 - I wonder if we might want to end up doing something with annotations here...

          Andrew Bayer added a comment - +1 - I wonder if we might want to end up doing something with annotations here...
          Jesse Glick made changes -
          Link New: This issue is related to JENKINS-35395 [ JENKINS-35395 ]

            jglick Jesse Glick
            abayer Andrew Bayer
            Votes:
            3 Vote for this issue
            Watchers:
            13 Start watching this issue

              Created:
              Updated:
              Resolved: