Groovy Help: Job DSL Plugin

68 views
Skip to first unread message

zealous...@gmail.com

unread,
Feb 26, 2015, 10:17:00 AM2/26/15
to job-dsl...@googlegroups.com
Hi,

I am a newbie to Groovy (playing catch up) and i have been trying to use the Job DSL Plugin. Everything works out great for me as long as i have everything in the DSL but i have a need to do it more programmatically. I looked through the Gradle DSL example and some more but couldn't find something which fits my need and works right.

Here is my use case (borrowing example from DSL playground)

job {
  name 'ci'
  description 'Build and test the app.'
  scm {
    git {
      remote {
        github 'sheehan/job-dsl-playground'
      }
    }
  }
  steps {
    gradle 'test'
  }
  publishers {
    archiveJunit 'build/test-results/**/*.xml'
  }
}

Now, i want to keep this DSL and i want to be able to attach the publishers section of this DSL by calling an API, something like


job {
    **** details taken out ***
    gradle 'test'
  }
  publishers  "${AnotherClass.configurePublishers()}"
}

How do i go about doing something like this?

Any pointers will be appreciated

Thanks

        

Patrick van Dissel

unread,
Feb 26, 2015, 10:32:54 AM2/26/15
to job-dsl...@googlegroups.com
Hey,

Check https://github.com/pvdissel/talk-jenkins-jobdsl
It contains sample JobDSL setups and a presentation that will guide you
through it.

Hope that clears things up for you :)
/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/0d9fb8f8-8c60-4109-9726-2263bcbad940%40googlegroups.com
> <https://groups.google.com/d/msgid/job-dsl-plugin/0d9fb8f8-8c60-4109-9726-2263bcbad940%40googlegroups.com?utm_medium=email&utm_source=footer>.
> For more options, visit https://groups.google.com/d/optout.

Matt Sheehan

unread,
Feb 26, 2015, 10:47:10 AM2/26/15
to job-dsl...@googlegroups.com
Each closure has a "delegate" variable that you can pass to other methods. Calling "with" on that variable allows you to call methods as you would in the DSL. So you can do something like this:

class AnotherClass {
  static void configurePublishers(publishersDelegate) {
    publishersDelegate.with {
      archiveJunit 'build/test-results/**/*.xml'
    }
  }
}

job {
  name 'ci'
  description 'Build and test the app.'
  scm {
    git {
      remote {
        github 'sheehan/job-dsl-playground'
      }
    }
  }
  steps {
    gradle 'test'
  }
  publishers {
    AnotherClass.configurePublishers(delegate)
  }
}

--
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.
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/0d9fb8f8-8c60-4109-9726-2263bcbad940%40googlegroups.com.
Message has been deleted

zealous...@gmail.com

unread,
Feb 27, 2015, 9:31:40 AM2/27/15
to job-dsl...@googlegroups.com
This was very helpful, thanks.
Reply all
Reply to author
Forward
0 new messages