Hi again!
This is another DSL change proposal motivated by the upcoming extension point.
The Job DSL plugin processes DSL scripts in two phases. In the first phase the scripts are executed to collect the XML data for all job, views, etc. In the second phase the collected data is used to update, create or delete jobs, views, etc.
As I mentioned in the other DSL changes post, a plugin using the DSL extension point can contribute a method to a context and return an object that is serialized to XML and inserted into the XML configuration data. That method will run during the first phase. A plugin using the DSL extension point should also be able to hook into the second phase to e.g. generate additional configuration files using data collected in the first phase. The question is how to transfer the data from the first phase to the second phase. I decided against storing the data in the config XML because that should just contain the data that is used to create jobs (view, etc) in Jenkins. Additional data must be stored elsewhere to carry it over from the first to the second phase. A natural key for that data would be the job (view, etc) name, but the name must no be set when an extension point method is called:
job {
steps {
myFooExtension('bar')
}
name('example')
}
I had a discussion with Thomas on the problem and he opened a pull request [1] which introduces an internal ID for jobs which can be used as key for the extension point data. While I'm sure that the change for the internal ID will work, I'm a bit uneasy about the addiontal complexity that it introduces.
When I went through the open issues in preparation of the last release, I found JENKINS-22323 [2] which proposes to change the DSL so that the name becomes a mandatory method parameter of the job (view, etc) method. I think that is a great idea, because mandatory parameters whould be method parameter anyway and it would not require an internal ID for the extension point, because the name will always be set:
job('example') {
steps {
myFooExtension('bar')
}
}
The only drawback is that the name must be set early, so helper methods probably need to be adjusted.
static createJob(def dslFactory) {
return dslFactory.job {
// set common options
}
}
def j = createJob(this)
j.with {
name 'example'
// additional settings
}
The example above must be changed to work with the proposed DSL change:
static createJob(def dslFactory, String jobName) {
return dslFactory.job(jobName) {
// set common options
}
}
def j = createJob(this, 'example')
j.with {
// additional settings
}
There will be a deprecation period for the existing job (view, etc) methods, but the new methods will have to be when using any extension point method.