• Icon: New Feature New Feature
    • Resolution: Fixed
    • Icon: Minor Minor
    • job-dsl-plugin
    • None

      It's very possible that someone will want to bring in an external library, which we're unfamiliar with or just don't include. If they could add an @Grab to get it, it's add up a lot of functionality.

      Comments / References from Original Github Issue

      andrewharmellaw referenced this issue 8 months ago
      Closed
      Issue #18: Facilitate DSL Extensions

      andrewharmellaw commented 8 months ago
      Sounds great. This is anther way of looking at the issue I created (#18). This is more idiomatic than mine though. I'll close it.

          [JENKINS-16361] @Grab Grape support

          I tried to implement the two solutions I suggested above.

          • Adding the Ivy library to jenkins.war works. The plugin does not need to be changed.
          • Adding the Groovy library to the plugin does not work so well. Fortunately no classloader magic on the plugin side is required since Jenkins can hide classes from a plugin when the plugin specifies a "Mask-Classes" attribute in the manifest. I implemented that in a branch, see https://github.com/CoreMedia/job-dsl-plugin/commit/830fae7a0fd8a046c620600e46633166804190e3. Script execution with @Grab works. Unfortunately this needs some workaround in the gradle build and currently breaks "gradlew server". The server does not start because it can not find the Groovy classes. It also breaks rendering the GeneratedJobsBuildAction with a java.lang.VerifyError when deploying to a running instance of Jenkins.

          Daniel Spilker added a comment - I tried to implement the two solutions I suggested above. Adding the Ivy library to jenkins.war works. The plugin does not need to be changed. Adding the Groovy library to the plugin does not work so well. Fortunately no classloader magic on the plugin side is required since Jenkins can hide classes from a plugin when the plugin specifies a "Mask-Classes" attribute in the manifest. I implemented that in a branch, see https://github.com/CoreMedia/job-dsl-plugin/commit/830fae7a0fd8a046c620600e46633166804190e3 . Script execution with @Grab works. Unfortunately this needs some workaround in the gradle build and currently breaks "gradlew server". The server does not start because it can not find the Groovy classes. It also breaks rendering the GeneratedJobsBuildAction with a java.lang.VerifyError when deploying to a running instance of Jenkins.

          Justin Ryan added a comment -

          Excellent research so far. I really need to get this working, so I'll try to find some time this week to review what you've found so far. Though I'm curious what problem you found by default, it sounded like an Ivy problem. And what problem did you see when you added Ivy to the plugin?

          Justin Ryan added a comment - Excellent research so far. I really need to get this working, so I'll try to find some time this week to review what you've found so far. Though I'm curious what problem you found by default, it sounded like an Ivy problem. And what problem did you see when you added Ivy to the plugin?

          When adding Ivy to the plugin without using "Mask-Classes", the exception is the same as without Ivy.

          Daniel Spilker added a comment - When adding Ivy to the plugin without using "Mask-Classes", the exception is the same as without Ivy.

          Justin Ryan added a comment -

          I think I got this figured out. Daniel, your research was spot on. There is no all-groovy or no-groovy solution, but there is a compromise. The trick is to just get Grape into the plugin classloader, so it can see the plugin's Ivy. I'll send you the code review.

          Justin Ryan added a comment - I think I got this figured out. Daniel, your research was spot on. There is no all-groovy or no-groovy solution, but there is a compromise. The trick is to just get Grape into the plugin classloader, so it can see the plugin's Ivy. I'll send you the code review.

          Justin Ryan added a comment -

          Justin Ryan added a comment - Can someone review: https://github.com/jenkinsci/job-dsl-plugin/pull/51

          Done. I'm giving 10 hours to see if anyone else wants to have a look too. Great work. Do you want to put something up on the wiki too? I created a "User Power Moves" page yesterday where this (using @Grab) would fit nicely...

          Andrew Harmel-Law added a comment - Done. I'm giving 10 hours to see if anyone else wants to have a look too. Great work. Do you want to put something up on the wiki too? I created a "User Power Moves" page yesterday where this (using @Grab) would fit nicely...

          Justin Ryan added a comment -

          Let's leave this open until after it's documented. I just started using this feature today, so give me a few days to clean it up to be used as an example. Thanks for adding the page.

          Justin Ryan added a comment - Let's leave this open until after it's documented. I just started using this feature today, so give me a few days to clean it up to be used as an example. Thanks for adding the page.

          Any indication of which version of Jenkins this is/will be available ?
          Also, does it matter whether the @Grab annotation is used from within the System console or a Groovy build step ?

          Patrice Matignon added a comment - Any indication of which version of Jenkins this is/will be available ? Also, does it matter whether the @Grab annotation is used from within the System console or a Groovy build step ?

          This ticket has been for the Job DSL plugin. For Grab support in the system console or the Groovy plugin you need to open another ticket.

          The Job DSL plugin has the Grab support for quite some time and works with Jenkins 1.480 or later. In principle, you can use the Job DSL plugin as a replacement for system Groovy build step provided by the Groovy plugin.

          Daniel Spilker added a comment - This ticket has been for the Job DSL plugin. For Grab support in the system console or the Groovy plugin you need to open another ticket. The Job DSL plugin has the Grab support for quite some time and works with Jenkins 1.480 or later. In principle, you can use the Job DSL plugin as a replacement for system Groovy build step provided by the Groovy plugin.

          Thanks for the quick reply. I had missed this ticket was indeed for the job-dsl-plugin. I will try what you suggest. Cheers!

          Patrice Matignon added a comment - Thanks for the quick reply. I had missed this ticket was indeed for the job-dsl-plugin. I will try what you suggest. Cheers!

            quidryan Justin Ryan
            andrewharmellaw Andrew Harmel-Law
            Votes:
            0 Vote for this issue
            Watchers:
            6 Start watching this issue

              Created:
              Updated:
              Resolved: