DSL Changes, Part II

71 vistas
Ir al primer mensaje no leído

Daniel Spilker

no leída,
14 feb 2015, 7:33:01 a.m.14/2/15
para job-dsl...@googlegroups.com
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.

So, what do you think? Make the changes sense to you? Any objections? Feedback is appreciated.

Daniel

[1] https://github.com/jenkinsci/job-dsl-plugin/pull/325
[2] https://issues.jenkins-ci.org/browse/JENKINS-22323

Patrick van Dissel

no leída,
14 feb 2015, 8:16:17 a.m.14/2/15
para job-dsl...@googlegroups.com
Hey,

Makes sense. This does mean the name becomes final and therefor cannot
be changed lateron within the dsl script. As you already mentioned this
will mean some rewrites of dsl scripts for (some?) users, I know I need
to change atleast some of mine :) But I believe this will only result in
cleaner scripts and therefor *thumbsup* :)

And that it keeps the JobDSL plugin code less complex is also a plus, of
course.

+1

/Patrick
> --
> You received this message because you are subscribed to the Google
> Groups "job-dsl-plugin" group.
> To unsubscribe from this group and stop receiving emails from it, send
> an email to job-dsl-plugi...@googlegroups.com
> <mailto:job-dsl-plugi...@googlegroups.com>.
> To post to this group, send email to job-dsl...@googlegroups.com
> <mailto:job-dsl...@googlegroups.com>.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/job-dsl-plugin/CAKqW32Buwi5Sk3Ck-fOcZaSWwF3hcS26%2B%3Dn%2B2W8URDNNjdXQfQ%40mail.gmail.com
> <https://groups.google.com/d/msgid/job-dsl-plugin/CAKqW32Buwi5Sk3Ck-fOcZaSWwF3hcS26%2B%3Dn%2B2W8URDNNjdXQfQ%40mail.gmail.com?utm_medium=email&utm_source=footer>.
> For more options, visit https://groups.google.com/d/optout.

Daniel Spilker

no leída,
21 feb 2015, 12:39:16 p.m.21/2/15
para job-dsl...@googlegroups.com
The name will not be final now, so scripts continue to work, but generate a lot of deprecation warnings. I will make the name final as part of the extension point branch.

Daniel

To unsubscribe from this group and stop receiving emails from it, send an email to job-dsl-plugi...@googlegroups.com.
To post to this group, send email to job-dsl...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/job-dsl-plugin/54DF4A9F.6090800%40gmail.com.
Responder a todos
Responder al autor
Reenviar
0 mensajes nuevos