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

Support for reusable sharing Declarative directives

      I'd like to be able to share recommended defaults for options directives. My initial use case was sharing steps through shared libraries.

       

      // vars/defaultOptionsConfig.groovy
      call() {
          timestamps()
      }
      
      options {
         defaultOptionsConfig()
         ansiColor('xterm')
      }

       

      At the same time, It'd also be nice to be able to be able to shared directives generally, so I didn't want to scope the request down too far.

       

      // vars/defaultOptions.groovy
      call() {
         options {
             timestamps()
         }
      }
      
      pipeline {
      ...
         defaultOptions()
         stages {
             ...
         }
      }

       

          [JENKINS-49135] Support for reusable sharing Declarative directives

          Robby Pocase created issue -

          I don't know if this is the place to ask for this, but I would like to extend this request to any part of the pipeline. I would like to be able to do:

          pipeline {
             defaultOptions()
             stages {
                  defaultStages()
                  stage("New Stage") {
                      defaultAgent()
                      steps {
                          // ...
                      }
                  }
              }
             defaultPost(sendEmail: true)
          }

          Leandro Lucarella added a comment - I don't know if this is the place to ask for this, but I would like to extend this request to any part of the pipeline. I would like to be able to do: pipeline { defaultOptions() stages { defaultStages() stage( "New Stage" ) { defaultAgent() steps { // ... } } } defaultPost(sendEmail: true ) }
          Andrew Bayer made changes -
          Summary Original: Support for reusable sharing option directives New: Support for reusable sharing Declarative directives

          Andrew Bayer added a comment -

          So what I'm verrrrry vaguely considering (absolutely no promises as to whether this will actually happen for practical and design reasons) would be supporting some directives, but not arbitrary ones. And it's definitely not going to happen any time in the near future.

          Andrew Bayer added a comment - So what I'm verrrrry vaguely considering (absolutely no promises as to whether this will actually happen for practical and design reasons) would be supporting some directives, but not arbitrary ones. And it's definitely not going to happen any time in the near future.
          Andrew Bayer made changes -
          Status Original: Open [ 1 ] New: In Progress [ 3 ]

          Andrew Bayer added a comment -

          Ok, I've got a super-preliminary work-in-progress up at https://github.com/jenkinsci/pipeline-model-definition-plugin/pull/241 - still no promises at all that this will actually land.

          It's not exactly what rpocase describes - no combination of "defaults" with additional entries, specification of the options contents would have to be in declaring a new Options object... More details are in the PR discussion, but here's roughly what this would look like:

          def opts = new Options([buildDiscarder(logRotator(numToKeepStr:'1'))], [:], [:])
          
          pipeline {
            ...
            options opts
            ...
          }
          
          // or
          
          def genOpts() {
              return new Options([buildDiscarder(logRotator(numToKeepStr: '1'))], [:], [:])
          }
          
          pipeline {
            ...
            options getOpts()
            ...
          }
          

          Andrew Bayer added a comment - Ok, I've got a super-preliminary work-in-progress up at https://github.com/jenkinsci/pipeline-model-definition-plugin/pull/241 - still no promises at all that this will actually land. It's not exactly what rpocase describes - no combination of "defaults" with additional entries, specification of the options contents would have to be in declaring a new Options object... More details are in the PR discussion, but here's roughly what this would look like: def opts = new Options([buildDiscarder(logRotator(numToKeepStr: '1' ))], [:], [:]) pipeline { ... options opts ... } // or def genOpts() { return new Options([buildDiscarder(logRotator(numToKeepStr: '1' ))], [:], [:]) } pipeline { ... options getOpts() ... }
          Andrew Bayer made changes -
          Remote Link New: This issue links to "PR #241 (Web Link)" [ 19945 ]

          Andrew Bayer added a comment -

          Oh, and as I mention in the PR, this definitely won't ever support all Declarative sections or directives. For example, anything that contains an actual step execution (so steps, post, when (in part because of when expression and in part because it'd be a pain in the ass), stage, and stages (because stage contains steps and stages contains stage) would not be supported. Nor would environment be supported. Main reason for that is because of how we handle steps and environment resolution in the AST transformation, plus that pushes even farther past what I'm comfortable with syntactically/complexity-wise than just things like options, triggers, parameters, tools, or agent.

          Andrew Bayer added a comment - Oh, and as I mention in the PR, this definitely won't ever support all Declarative sections or directives. For example, anything that contains an actual step execution (so steps , post , when (in part because of when expression and in part because it'd be a pain in the ass), stage , and stages (because stage contains steps and stages contains stage ) would not be supported. Nor would environment be supported. Main reason for that is because of how we handle steps and environment resolution in the AST transformation, plus that pushes even farther past what I'm comfortable with syntactically/complexity-wise than just things like options , triggers , parameters , tools , or agent .

          Cool! That looks like a reasonable approach. I hope it lands eventually!

          Leandro Lucarella added a comment - Cool! That looks like a reasonable approach. I hope it lands eventually!

          Hi abayer, can you elaborate a little more on why it'd be a pain in the ass to support stages? Because I feel like you wouldn't be very happy about JENKINS-50548 then...

          Tobias Larscheid added a comment - Hi abayer , can you elaborate a little more on why it'd be a pain in the ass to support stages? Because I feel like you wouldn't be very happy about JENKINS-50548  then...

            Unassigned Unassigned
            rpocase Robby Pocase
            Votes:
            27 Vote for this issue
            Watchers:
            37 Start watching this issue

              Created:
              Updated: