Details

    • Type: Improvement
    • Status: Closed (View Workflow)
    • Priority: Minor
    • Resolution: Not A Defect
    • Component/s: job-dsl-plugin
    • Labels:
    • Environment:
      Jenkins 2.92, bitbucket-branch 2.2.7, cloudbees-folder 6.2.1, job-dsl 1.66
    • Similar Issues:

      Description

      While trying the implement DSL configuration using Bitbucket Branch, I'm not able to implement orphanedItemStrategy. It defaults to a DefaultOrphanedItemStrategyContext, that do not exist on DSL API.

      Error:

      ERROR: (script, line 12) No signature of method: javaposse.jobdsl.dsl.helpers.workflow.DefaultOrphanedItemStrategyContext.daysToKeep() is applicable for argument types: (java.lang.String) values: [10]
      Possible solutions: daysToKeep(int), getDaysToKeep(), setDaysToKeep(int), numToKeep(int)
      

      Looking into a manually configured Bitbucket Branch based build config.xml file, it shows that orphanedItemStrategy is implemented by cloudbees-folder.

      <orphanedItemStrategy class="com.cloudbees.hudson.plugins.folder.computed.DefaultOrphanedItemStrategy" plugin="cloudbees-folder@6.2.1">
          <pruneDeadBranches>false</pruneDeadBranches>
          <daysToKeep>-1</daysToKeep>
          <numToKeep>-1</numToKeep>
        </orphanedItemStrategy>
      

      Bitbucket Branch implements OrganizationFolder and expanding orphanedItemStrategy, does not show the same configurations as in the xml file.

      Test DSL script:

      organizationFolder('My DSL Folder test'){
          displayName('my_display_name')
          description('my_description')
          orphanedItemStrategy {
              discardOldItems {
                  daysToKeep('10')
                  numToKeep('10')
              }
          }
          organizations {
              bitbucket {
                  repoOwner('my_repo_code')
                  credentialsId('my_cred_id')
                  serverUrl('my_server_url')
              }
          }
      }
      

      To me, this seems a case of missing DSL configuration but not sure by which component.

        Attachments

          Activity

          Hide
          ncosta Nuno Costa added a comment -

          Workaround using configure block:

          configure { organizationFolder ->
                organizationFolder / orphanedItemStrategy(class: 'com.cloudbees.hudson.plugins.folder.computed.DefaultOrphanedItemStrategy'){
                      pruneDeadBranches('false')
                      daysToKeep('-1')
                      numToKeep('-1')
                  }
              }
          
          Show
          ncosta Nuno Costa added a comment - Workaround using configure block: configure { organizationFolder ->       organizationFolder / orphanedItemStrategy(class: 'com.cloudbees.hudson.plugins.folder.computed.DefaultOrphanedItemStrategy' ){             pruneDeadBranches( ' false ' )             daysToKeep( '-1' )             numToKeep( '-1' )         }     }
          Hide
          daspilker Daniel Spilker added a comment -

          The daysToKeep and numToKeep options take an integer value, but you provided a string value.

          Try this:

          organizationFolder('My DSL Folder test'){
              displayName('my_display_name')
              description('my_description')
              orphanedItemStrategy {
                  discardOldItems {
                      daysToKeep(10)
                      numToKeep(10)
                  }
              }
              organizations {
                  bitbucket {
                      repoOwner('my_repo_code')
                      credentialsId('my_cred_id')
                      serverUrl('my_server_url')
                  }
              }
          }
          
          Show
          daspilker Daniel Spilker added a comment - The daysToKeep and numToKeep options take an integer value, but you provided a string value. Try this: organizationFolder( 'My DSL Folder test' ){ displayName( 'my_display_name' ) description( 'my_description' ) orphanedItemStrategy { discardOldItems { daysToKeep(10) numToKeep(10) } } organizations { bitbucket { repoOwner( 'my_repo_code' ) credentialsId( 'my_cred_id' ) serverUrl( 'my_server_url' ) } } }
          Hide
          ncosta Nuno Costa added a comment -

          Daniel Spilker, thanks for pointing that out.

          Not using the single quotes when setting daysToKeep and numToKeep options, worked OK.

          Meanwhile, I noticed that pruneDeadBranches does not seems to exist. Tried with pruneDeadBranches('false'), pruneDeadBranches(False) and pruneDeadBranches(false) but they fail with:

          ERROR: (add_jobs.groovy, line 7) No signature of method: javaposse.jobdsl.dsl.helpers.workflow.DefaultOrphanedItemStrategyContext.pruneDeadBranches() is applicable for argument types: (java.lang.String) values: [false]
          
          ERROR: (add_jobs.groovy, line 7) No such property: False for class: javaposse.jobdsl.dsl.helpers.workflow.DefaultOrphanedItemStrategyContext
          Possible solutions: class
          
          ERROR: (add_jobs.groovy, line 7) No signature of method: javaposse.jobdsl.dsl.helpers.workflow.DefaultOrphanedItemStrategyContext.pruneDeadBranches() is applicable for argument types: (java.lang.Boolean) values: [false]
          

          I did not see an entry for pruneDeadBranches on DSL API.

          If orphanedItemStrategy block is omited, project will have the Discard old items set to true with no values set for daysToKeep and numToKeep. Added a screenshot. config.xml snippet below:

          <orphanedItemStrategy class="com.cloudbees.hudson.plugins.folder.computed.DefaultOrphanedItemStrategy">
              <pruneDeadBranches>true</pruneDeadBranches>
              <daysToKeep>0</daysToKeep>
              <numToKeep>0</numToKeep>
          </orphanedItemStrategy>
          

          It works when using the configure block, as I mention on my first comment. Should this be reported on a different issue?

          Show
          ncosta Nuno Costa added a comment - Daniel Spilker , thanks for pointing that out. Not using the single quotes when setting daysToKeep and numToKeep options, worked OK. Meanwhile, I noticed that pruneDeadBranches does not seems to exist. Tried with pruneDeadBranches('false') , pruneDeadBranches(False) and pruneDeadBranches(false) but they fail with: ERROR: (add_jobs.groovy, line 7) No signature of method: javaposse.jobdsl.dsl.helpers.workflow.DefaultOrphanedItemStrategyContext.pruneDeadBranches() is applicable for argument types: (java.lang. String ) values: [ false ] ERROR: (add_jobs.groovy, line 7) No such property: False for class: javaposse.jobdsl.dsl.helpers.workflow.DefaultOrphanedItemStrategyContext Possible solutions: class ERROR: (add_jobs.groovy, line 7) No signature of method: javaposse.jobdsl.dsl.helpers.workflow.DefaultOrphanedItemStrategyContext.pruneDeadBranches() is applicable for argument types: (java.lang. Boolean ) values: [ false ] I did not see an entry for pruneDeadBranches on DSL API. If orphanedItemStrategy block is omited, project will have the Discard old items set to true with no values set for daysToKeep and numToKeep . Added a screenshot. config.xml snippet below: <orphanedItemStrategy class= "com.cloudbees.hudson.plugins.folder.computed.DefaultOrphanedItemStrategy" > <pruneDeadBranches> true </pruneDeadBranches> <daysToKeep>0</daysToKeep> <numToKeep>0</numToKeep> </orphanedItemStrategy> It works when using the configure block, as I mention on my first comment. Should this be reported on a different issue?
          Hide
          daspilker Daniel Spilker added a comment -

          Nuno Costa Instead of trying to guess the syntax, you can have a look at the Job DSL API viewer. It will also show the expected parameter type. Either use the online version at https://jenkinsci.github.io/job-dsl-plugin/ or, even better since it will also contain the Automatically Generated DSL, use the embedded API viewer in your Jenkins instance at <JENKINS_HOST>/plugin/job-dsl/api-viewer/index.html.

          pruneDeadBranches is not supported yet, but you can use a Configure Block to add any missing option.

          I opened a pull request to enable the Automatically Generated DSL for the orphaned items strategy: https://github.com/jenkinsci/job-dsl-plugin/pull/1107

          That PR will enable this syntax using the Automatically Generated DSL:

          organizationFolder('My DSL Folder test') {
              orphanedItemStrategy {
                  defaultOrphanedItemStrategy {
                      pruneDeadBranches(false)
                      daysToKeepStr('10')
                      numToKeepStr('10')
                  } 
              }
          }
          
          Show
          daspilker Daniel Spilker added a comment - Nuno Costa Instead of trying to guess the syntax, you can have a look at the Job DSL API viewer. It will also show the expected parameter type. Either use the online version at https://jenkinsci.github.io/job-dsl-plugin/ or, even better since it will also contain the Automatically Generated DSL , use the embedded API viewer in your Jenkins instance at <JENKINS_HOST>/plugin/job-dsl/api-viewer/index.html. pruneDeadBranches is not supported yet, but you can use a Configure Block to add any missing option. I opened a pull request to enable the Automatically Generated DSL for the orphaned items strategy: https://github.com/jenkinsci/job-dsl-plugin/pull/1107 That PR will enable this syntax using the Automatically Generated DSL: organizationFolder( 'My DSL Folder test' ) { orphanedItemStrategy { defaultOrphanedItemStrategy { pruneDeadBranches( false ) daysToKeepStr( '10' ) numToKeepStr( '10' ) } } }
          Hide
          ncosta Nuno Costa added a comment -

          Daniel Spilker thanks, for the PR.

          Show
          ncosta Nuno Costa added a comment - Daniel Spilker thanks, for the PR.

            People

            • Assignee:
              daspilker Daniel Spilker
              Reporter:
              ncosta Nuno Costa
            • Votes:
              1 Vote for this issue
              Watchers:
              3 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved: