Integrating promoted-builds DSL to a job-dsl-gradle-example project

89 views
Skip to first unread message

François Genois

unread,
Jun 1, 2016, 10:36:55 AM6/1/16
to Jenkins Users
Good morning everyone,

I'm currently using a project based on https://github.com/sheehan/job-dsl-gradle-example and I am trying to get the promoted-builds plugin to work with this project (https://wiki.jenkins-ci.org/display/JENKINS/Promoted+Builds+Plugin).

Everything works fine on my Jenkins server (with the plugin installed), but I can't figure out a way to make my code work on this local project. I use this project to work locally, to debug and to test; instead of sending it to the server for every single modifications.

Here is an example project that reproduces my problem :

And here one of the ways I run it locally :
gradlew debugXml -Dpattern=jobs/example1Jobs.groovy

I'm not quite sure if this is a limitation/bug/feature_request or if it is simply me having a hard time to make it work.

Please help me and I wish you a nice day!

- Frank

Thomas Zoratto

unread,
Jun 1, 2016, 12:20:01 PM6/1/16
to jenkins...@googlegroups.com
Hello Frank, 

I guess the promoted builds plugin is not directly compatible with the job DSL plugin. I mean you can’t find DSL methods relative to the promoted builds plugin in the online API https://github.com/franknarf8/job-dsl-gradle-example/commit/f15b7fbf698d7be29b8527043d8649ab15559842

I think the job DSL plugin must use the extension point when in the context of a running instance with the promoted builds plugin installed.

Though, I suppose you can test it locally thanks to the last updates of sheehan's github repo. See https://github.com/sheehan/job-dsl-gradle-example/commit/9d6260b44cefdd832ee3f854f107b24f15881ea7. You’ll have to specify the plugins you have in your running instance in order to simulate a similar environment for your local tests.

sorry for my poor English !

Thomas

--
You received this message because you are subscribed to the Google Groups "Jenkins Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to jenkinsci-use...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/jenkinsci-users/596540e7-63dc-49c2-9532-be154aafd98d%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

François Genois

unread,
Jun 1, 2016, 2:35:54 PM6/1/16
to Jenkins Users
Hello Thomas,

Thank you very much for your answer.
The promoted builds plugin is indeed a extension point.

I added the following line to my dependencies "testCompile 'org.jenkins-ci.plugins:promoted-builds:2.27@jar'" and my 'gradlew test' command now succeeds.

I just tried applying the same logic to the 'debugXml' gradle task (I use the XML to verify if I haven't done any regression during refactoring), but I can't figure out how to make this code run in a context running an instance of the promoted-builds plugin.

Do you have an idea of how I could get the XML generated from the scripts?

Thank you again and have a nice day!

- Frank

Thomas Zoratto

unread,
Jun 1, 2016, 3:40:22 PM6/1/16
to jenkins...@googlegroups.com
Right now I can’t see a way to do this but my knowledge on this topic is very limited. I also have to work on it soon so I’ll let you know if I find a way (and if you still don’t have the answer).

Please share your progress, if any 

Good luck !

Thomas


François Genois

unread,
Jun 1, 2016, 5:04:27 PM6/1/16
to jenkins...@googlegroups.com
Ok, I'm pretty much in the same situation over here. Alright, I'm looking forward your advancement on this issue; I'll keep you updated if I find anything.

Thanks again!

- Frank

You received this message because you are subscribed to a topic in the Google Groups "Jenkins Users" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/jenkinsci-users/ZC-XZbrEz1s/unsubscribe.
To unsubscribe from this group and all its topics, send an email to jenkinsci-use...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/jenkinsci-users/4E2786B1-62C5-47CB-A595-463E41CC491F%40gmail.com.

François Genois

unread,
Jun 7, 2016, 11:20:03 AM6/7/16
to Jenkins Users
Information for all (and for Thomas) :

I was able to output the XML files in a not-clean-not-proud way :
I copied the JenkinsJobManagement file (to remove the 'final' keyword from it that class) and I subclassed it as MemoryJobManagement subclasses MockJobManagement.
I needed to add logging logic to some of the calls of JenkinsJobManagement (wraping JenkinsJobManagement would have been very unpleasant, but subclassing it is really pretty)
Anyway, here is an example outputting XML if you run 'gradlew test'.

Thanks again and have a nice day!

- Frank
To unsubscribe from this group and stop receiving emails from it, send an email to jenkinsci-users+unsubscribe@googlegroups.com.

--
You received this message because you are subscribed to a topic in the Google Groups "Jenkins Users" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/jenkinsci-users/ZC-XZbrEz1s/unsubscribe.
To unsubscribe from this group and all its topics, send an email to jenkinsci-users+unsubscribe@googlegroups.com.

Thomas Zoratto

unread,
Jun 7, 2016, 1:16:12 PM6/7/16
to jenkins...@googlegroups.com
Hi, 

thanks for this update. I still don’t have time to try something about it but I will…! 


Thomas Zoratto

unread,
Jun 18, 2016, 12:49:54 PM6/18/16
to jenkins...@googlegroups.com
Hello, 

I came up with a solution that doesn’t involve overwriting class, subclass etc.

You just have to use the JenkinsRule object in your test in order to use the API of the running Jenkins instance.

e.g. jenkinsRule.jenkins.getAllItems()…

Then you can retrieve the config.xml generated for each job/view. Tested here and it works.

But I have good news for you, JenkinsJobManagement is no longer final thanks to a recent commit (see https://github.com/jenkinsci/job-dsl-plugin/commit/930aa4818a3ff74494696b14c241a521bc75c0a9). We have to wait for the next release though.

Wisen Tanasa

unread,
Aug 23, 2016, 12:28:55 PM8/23/16
to Jenkins Users
I couldn't get a way to grab the config.xml files nicely from jenkinsRule.jenkins.getAllItems(). This is what I ended up doing to get the config.xml files. I kind of like this approach as I don't have to handle config.xml that are not from Jenkins Item e.g. promoted builds generate config.xml under job/promotions/promotion-name/config.xml.

@AfterClass
public void exportConfigXml() {
def generatedJobsDirectory = new File(jenkinsRule.instance.root, 'jobs')
def targetDirectory = new File('target')
targetDirectory.mkdir()

FileUtils.copyDirectory(generatedJobsDirectory, targetDirectory,
new OrFileFilter([DirectoryFileFilter.INSTANCE, new NameFileFilter('config.xml')]))
}
To unsubscribe from this group and stop receiving emails from it, send an email to jenkinsci-users+unsub...@googlegroups.com.

-- 
You received this message because you are subscribed to a topic in the Google Groups "Jenkins Users" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/jenkinsci-users/ZC-XZbrEz1s/unsubscribe.
To unsubscribe from this group and all its topics, send an email to jenkinsci-users+unsub...@googlegroups.com.

-- 
You received this message because you are subscribed to the Google Groups "Jenkins Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to jenkinsci-users+unsub...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages