How can I set the job timeout for all jobs using the Jenkins DSL
<p>I read <a href="https://stackoverflow.com/questions/31818602/how-can-i-set-the-job-timeout-using-the-jenkins-dsl">How can I set the job timeout using the Jenkins DSL</a>. That sets the timeout for one job. I want to set it for all jobs, and with slightly different settings: 150%, averaged over 10 jobs, with a max of 30 minutes.</p>

<p>According to the <a href="https://github.com/jenkinsci/job-dsl-plugin/blob/master/job-dsl-core/src/main/docs/examples/javaposse/jobdsl/dsl/helpers/wrapper/WrapperContext/timeout.groovy" rel="nofollow noreferrer">relevant job-dsl-plugin documentation</a> I should use this syntax:</p>

<pre><code>job('example-3') {
    wrappers {
        timeout {
            elastic(150, 10, 30)
            failBuild()
            writeDescription('Build failed due to timeout after {0} minutes')
        }
    }
}
</code></pre>

<p>I tested in <a href="http://job-dsl.herokuapp.com/" rel="nofollow noreferrer">http://job-dsl.herokuapp.com/</a> and this is the relevant XML part:</p>

<pre><code>&lt;buildWrappers&gt;
    &lt;hudson.plugins.build__timeout.BuildTimeoutWrapper&gt;
        &lt;strategy class='hudson.plugins.build_timeout.impl.ElasticTimeOutStrategy'&gt;
            &lt;timeoutPercentage&gt;150&lt;/timeoutPercentage&gt;
            &lt;numberOfBuilds&gt;10&lt;/numberOfBuilds&gt;
            &lt;timeoutMinutesElasticDefault&gt;30&lt;/timeoutMinutesElasticDefault&gt;
        &lt;/strategy&gt;
        &lt;operationList&gt;
            &lt;hudson.plugins.build__timeout.operations.FailOperation&gt;&lt;/hudson.plugins.build__timeout.operations.FailOperation&gt;
            &lt;hudson.plugins.build__timeout.operations.WriteDescriptionOperation&gt;
                &lt;description&gt;Build failed due to timeout after {0} minutes&lt;/description&gt;
            &lt;/hudson.plugins.build__timeout.operations.WriteDescriptionOperation&gt;
        &lt;/operationList&gt;
    &lt;/hudson.plugins.build__timeout.BuildTimeoutWrapper&gt;
&lt;/buildWrappers&gt;
</code></pre>

<p>I verified with a job I edited manually before, and the XML is correct. So I know that the Jenkins DSL syntax up to here is correct.</p>

<hr>

<p>Now I want to apply this to all jobs. First I tried to list all the job names:</p>

<pre><code>import jenkins.model.*

jenkins.model.Jenkins.instance.items.findAll().each {
  println("Job: " + it.name)
}
</code></pre>

<p>This works too, all job names are printed to console.</p>

<hr>

<p>Now I want to plug it all together. This is the full code I use:</p>

<pre><code>import jenkins.model.*

jenkins.model.Jenkins.instance.items.findAll().each {
  job(it.name) {
    wrappers {
      timeout {
        elastic(150, 10, 30)
        failBuild()
        writeDescription('Build failed due to timeout after {0} minutes')
      }
    }
  }
}
</code></pre>

<p>When I push this code and Jenkins runs the DSL seed job, I get this error:</p>

<pre><code>ERROR: Type of item "jobname" does not match existing type, item type can not be changed
</code></pre>

<p>What am I doing wrong here?</p>