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

Allow Scriptler to be used in Conditional BuildStep plugin

    • Icon: Improvement Improvement
    • Resolution: Unresolved
    • Icon: Major Major
    • scriptler-plugin
    • None

      When using the conditional buildstep plugin it is not possible to select Scriptler as builder.

      This seems to be related to JENKINS-15445: Conditional BuildStep only checks for builders with the @DataBoundConstructor annotation which is missing in the ScriptlerBuilder constructor. I already tried adding the annotation, so Scriptler becomes selectable. I can also set the groovy script to execute and the parameters, but: neither the "scriptId" nor the "parameters" are stored in the project! Funny though, the "propagateParams" flag is stored.

      Using Scriptler as builder by it's own did work ok, by the way. I haven't done any further tests with the annotation and i actually don't know what "bad" influence it could have. And maybe the "unsaved" scriptId and parameters are related to some other bug.

          [JENKINS-15975] Allow Scriptler to be used in Conditional BuildStep plugin

          Unfortunate this is not as easy as it might look. When saving a job configuration which contains a scriplter builder, then a check to see whether the user is actually allowed to change a scriptler configuration. If not, then the old scriplter-builder config is restored and only the parts of the job are updated. This check is currently not possible with a DataBoundConstructor and therefore I'm not able to implement this at the current time

          Dominik Bartholdi added a comment - Unfortunate this is not as easy as it might look. When saving a job configuration which contains a scriplter builder, then a check to see whether the user is actually allowed to change a scriptler configuration. If not, then the old scriplter-builder config is restored and only the parts of the job are updated. This check is currently not possible with a DataBoundConstructor and therefore I'm not able to implement this at the current time

          Markus Hoofe added a comment -

          Well, that's a pity, as it would have been very useful. But fortunately, it is still possible to use the script itself to check the condition.

          Markus Hoofe added a comment - Well, that's a pity, as it would have been very useful. But fortunately, it is still possible to use the script itself to check the condition.

          Oleg Nenashev added a comment -

          Workaround: Use "Template Project" plugin. You can include Scriptler calls from a remote job inside conditional steps

          Oleg Nenashev added a comment - Workaround: Use "Template Project" plugin. You can include Scriptler calls from a remote job inside conditional steps

          What I suggest should but does not work!: Use the scriptlet as a regular Groovy script and pass it command line arguments instead of the scriptlet parameters. You need to make small modifications to your scriptlet to work with command line arguments AND parameters. Every Groovy script has an implicit args String[] that represents the command line arguments passed into the script.
          So if we had a hello.groovy scriptlet with one defined vName parameter. We would write a standard scriptlet as:

          name=vName
          println "Hello $name"
          

          We could adapt this as follows to work with one command line argument like this:
          >groovy hello.groovy John

          name=''
          if (args){
          name=args[0]
          }else{
          name=vName
          }
          println "Hello $name"
          

          When the code above is executed in a Jenkins Conditional Build setp as a Groovy script it works fine. But when you try to execute the script as a scriptlet, the implicit 'args' parameter is not recognized

          You get a 'MissingPropertyException: No such property: args for class: Script1' error

          Ioannis Moutsatsos added a comment - What I suggest should but does not work!: Use the scriptlet as a regular Groovy script and pass it command line arguments instead of the scriptlet parameters. You need to make small modifications to your scriptlet to work with command line arguments AND parameters. Every Groovy script has an implicit args String[] that represents the command line arguments passed into the script. So if we had a hello.groovy scriptlet with one defined vName parameter. We would write a standard scriptlet as: name=vName println "Hello $name" We could adapt this as follows to work with one command line argument like this: > groovy hello.groovy John name='' if (args){ name=args[0] } else { name=vName } println "Hello $name" When the code above is executed in a Jenkins Conditional Build setp as a Groovy script it works fine. But when you try to execute the script as a scriptlet, the implicit 'args' parameter is not recognized You get a ' MissingPropertyException: No such property: args for class: Script1 ' error

            domi Dominik Bartholdi
            mhoofe Markus Hoofe
            Votes:
            5 Vote for this issue
            Watchers:
            7 Start watching this issue

              Created:
              Updated: