title: How to bulk update Jenkins jobs config xml files?
body: <p>I'm a newbie in Jenkins and Groovy. I need to bulk update Jenkins jobs config files. For example, changing the Git URL for a large number of jobs or adding a timeout behaviour. To do that I'm generating a list of Jenkins job names using this piece of Groovy code:</p>
  
  <pre><code>import com.cloudbees.hudson.plugins.folder.*
  void processFolder(Item folder) {
      folder.getItems().each {
          if(it instanceof Folder) {
              processFolder(it)
          } else {
              processJob(it)
          }
      }
  }
  
  void processJob(Item job) {
      println job.fullName
  }
  
  Jenkins.instance.getItems().each {
      if(it instanceof Folder) {
          processFolder(it)
      } else {
          processJob(it)
      }
  }
  </code></pre>
  
  <p>Inside processJob() method, I'm planning to fetch the job's config file using job name</p>
  
  <pre><code>void processJob(Item job) {
      AbstractItem item = (AbstractItem)Jenkins.getInstance().getItem(job.name);
      XmlFile configXml = item.getConfigFile();
      File xmlfile = configXml.getFile();
      def xml = new XmlParser().parse(xmlfile)
  }
  </code></pre>
  
  <p>Sample config file:</p>
  
  <pre><code>&lt;?xml version='1.0' encoding='UTF-8'?&gt;
  &lt;project&gt;
    &lt;actions/&gt;
    &lt;description&gt;&lt;/description&gt;
    &lt;keepDependencies&gt;false&lt;/keepDependencies&gt;
    &lt;properties/&gt;
    &lt;scm class="hudson.plugins.git.GitSCM" plugin="git@3.4.1"&gt;
      &lt;configVersion&gt;2&lt;/configVersion&gt;
      &lt;userRemoteConfigs&gt;
        &lt;hudson.plugins.git.UserRemoteConfig&gt;
          &lt;url&gt;https://github.com/gitboy/Backup.git&lt;/url&gt;
        &lt;/hudson.plugins.git.UserRemoteConfig&gt;
      &lt;/userRemoteConfigs&gt;
      &lt;branches&gt;
        &lt;hudson.plugins.git.BranchSpec&gt;
          &lt;name&gt;*/master&lt;/name&gt;
        &lt;/hudson.plugins.git.BranchSpec&gt;
      &lt;/branches&gt;
  &lt;/project&gt;
  </code></pre>
  
  <p>Here I need to add a new element TIMEOUT after the URL tag.</p>
  
  <p>But the XmlParser gives an output that looks something like this: </p>
  
  <pre><code>project[attributes={}; value=[actions[attributes={}; value=[]], 
  description[attributes={}; value=[]], keepDependencies[attributes={}; value=
  [false]], properties[attributes={}; value=[]], scm[attributes=
  {class=hudson.plugins.git.GitSCM, plugin=git@3.4.1}; value=
  [configVersion[attributes={}; value=[2]], userRemoteConfigs[attributes={}; 
  value=[hudson.plugins.git.UserRemoteConfig[attributes={}; value=
  [url[attributes={}; value=
  [https://github.com/gitboy/Backup.git]]]]]], 
  branches[attributes={}; value=[hudson.plugins.git.BranchSpec[attributes={}; 
  value=[name[attributes={}; value=[*/master]]]]]]]
  </code></pre>
  
  <p>I couldn't find any examples on how to add a new child element using XmlParser/XmlSlurper.</p>
  
  <p>Is it the right approach to bulk update Jenkins jobs configuration? Appreciate any help/suggestion.</p>
  
  <p>Thanks in advance!</p>