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

Preserve existing properties when replacing folder with Job DSL script

    XMLWordPrintable

    Details

    • Similar Issues:

      Description

      I would like to manually modify credentials in Jenkins folders and multibranch pipelines (a folder type).

      When generating a job credentials are removed. It would be nice if Job DSL read the properties of an existing job and merged or overwrote duplicates when creating the new job.

        Attachments

          Activity

          Hide
          sag47 Sam Gleske added a comment -

          I've figured out how to get properties as an XML string from an existing job. Currently trying to figure out how to integrate it with the configure block in the mean time. Refer to https://github.com/samrocketman/jervis/issues/117

          Show
          sag47 Sam Gleske added a comment - I've figured out how to get properties as an XML string from an existing job. Currently trying to figure out how to integrate it with the configure block in the mean time. Refer to https://github.com/samrocketman/jervis/issues/117
          Hide
          daspilker Daniel Spilker added a comment -

          Job DSL always replaces the complete configuration. You have to declare the complete config in the script.

          But you can use the Jenkins API to copy parts of the existing config to the generated config:

          import jenkins.model.Jenkins
          import hudson.model.Items
          
          def nodes = []
          def item = Jenkins.instance.getItem('example-mbp')
          if (item) {
            def parser = new XmlParser()
            nodes = item.properties.collect { 
              parser.parseText(Items.XSTREAM2.toXML(it))
            }
          }
          
          multibranchPipelineJob('example-mbp') {
            configure {
              def propertiesNode = it / 'properties'
              nodes.each {
                propertiesNode.append(it)
              }
            }
          }
          
          Show
          daspilker Daniel Spilker added a comment - Job DSL always replaces the complete configuration. You have to declare the complete config in the script. But you can use the Jenkins API to copy parts of the existing config to the generated config: import jenkins.model.Jenkins import hudson.model.Items def nodes = [] def item = Jenkins.instance.getItem( 'example-mbp' ) if (item) { def parser = new XmlParser() nodes = item.properties.collect { parser.parseText(Items.XSTREAM2.toXML(it)) } } multibranchPipelineJob( 'example-mbp' ) { configure { def propertiesNode = it / 'properties' nodes.each { propertiesNode.append(it) } } }

            People

            • Assignee:
              daspilker Daniel Spilker
              Reporter:
              sag47 Sam Gleske
            • Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved: