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

Allow adding new JobProperty values instead of replacing

XMLWordPrintable

    • Icon: Improvement Improvement
    • Resolution: Unresolved
    • Icon: Minor Minor
    • None
    • Jenkins 2.235.1

      I would like to add new job properties to a multibranch pipeline in a pipeline library.

      The idea is to simplify building projects with a `buildProject()` step.

      As part of this step I would like to set the following properties by default:

      properties([
        disableConcurrentBuilds(),
        disableResume(),
        durabilityHint('PERFORMANCE_OPTIMIZED'),
      ])
      

      However, if I also define properties in the main Jenkinsfile, those are overwritted by the pipeline library step.

      I have seen in other issues that this is the intended behaviour of the properties() step.

      Would it be possible to add new steps that add/remove properties (e.g. addJobProperties/removeJobProperties)?

       

      I tried adding a addJobProperties() helper, but was not able to convert the result of the pipeline helpers such as disableResume() to a JobProperty<?>. I am not familiar with the internals of the pipeline/jenkins code so maybe there is a easy way to make the prop as JobProperty<?> line work:

       

      @NonCPS
      def call(List/*<JobProperty<?>>*/ args) {
          hudson.model.Job<?, ?> job = currentBuild.rawBuild.parent;
          echo("Properties before:")
          job.getAllProperties().eachWithIndex{ JobProperty<?> entry, int i ->
              echo("Property ${i}: ${entry.toString()}")
          }
          echo("Properties before:")
          for (/*<JobProperty<?>*/ prop in args) {
              job.addProperty(prop as JobProperty<?>);
          }
          echo("Properties after:")
          job.getAllProperties().eachWithIndex{ JobProperty<?> entry, int i ->
              echo("Property ${i}: ${entry.toString()}")
          }
      }
      

       

            Unassigned Unassigned
            arichardson Alex Richardson
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated: