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')]))
}


On Saturday, June 18, 2016 at 5:49:54 PM UTC+1, Thomas Zoratto wrote:
>
> 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.
>
> Le 7 juin 2016 à 17:20, François Genois <[email protected] 
> <javascript:>> a écrit :
>
> 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'.
>
> https://github.com/franknarf8/job-dsl-gradle-example/tree/03524daa83851a544106cc514591026a99f3ee64
>
> Thanks again and have a nice day!
>
> - Frank
>
>
> On Wednesday, June 1, 2016 at 5:04:27 PM UTC-4, François Genois wrote:
>>
>> 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
>>
>> On Wed, Jun 1, 2016 at 3:40 PM Thomas Zoratto <[email protected] 
>> <javascript:>> wrote:
>>
>>> 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
>>>
>>>
>>> Le 1 juin 2016 à 20:35, François Genois <[email protected] 
>>> <javascript:>> a écrit :
>>>
>>> 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
>>>
>>>
>>> On Wednesday, June 1, 2016 at 12:20:01 PM UTC-4, Thomas Zoratto wrote:
>>>>
>>>> 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
>>>>
>>>> Le 1 juin 2016 à 16:36, François Genois <[email protected]> a écrit 
>>>> :
>>>>
>>>> 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 :
>>>>
>>>> https://github.com/franknarf8/job-dsl-gradle-example/commit/f15b7fbf698d7be29b8527043d8649ab15559842
>>>>
>>>> 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
>>>>
>>>> -- 
>>>> 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 [email protected].
>>>> To view this discussion on the web visit 
>>>> https://groups.google.com/d/msgid/jenkinsci-users/596540e7-63dc-49c2-9532-be154aafd98d%40googlegroups.com
>>>>  
>>>> <https://groups.google.com/d/msgid/jenkinsci-users/596540e7-63dc-49c2-9532-be154aafd98d%40googlegroups.com?utm_medium=email&utm_source=footer>
>>>> .
>>>> For more options, visit https://groups.google.com/d/optout.
>>>>
>>>>
>>>>
>>> -- 
>>> 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 [email protected] <javascript:>.
>>>
>>>
>>> To view this discussion on the web visit 
>>> https://groups.google.com/d/msgid/jenkinsci-users/c5fbe124-2007-4d58-9daa-35bf41cbf1ea%40googlegroups.com
>>>  
>>> <https://groups.google.com/d/msgid/jenkinsci-users/c5fbe124-2007-4d58-9daa-35bf41cbf1ea%40googlegroups.com?utm_medium=email&utm_source=footer>
>>> .
>>> For more options, visit https://groups.google.com/d/optout.
>>>
>>>
>>> -- 
>>> 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 
>>> [email protected] <javascript:>.
>>> To view this discussion on the web visit 
>>> https://groups.google.com/d/msgid/jenkinsci-users/4E2786B1-62C5-47CB-A595-463E41CC491F%40gmail.com
>>>  
>>> <https://groups.google.com/d/msgid/jenkinsci-users/4E2786B1-62C5-47CB-A595-463E41CC491F%40gmail.com?utm_medium=email&utm_source=footer>
>>> .
>>> For more options, visit https://groups.google.com/d/optout.
>>>
>>
> -- 
> 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 [email protected] <javascript:>.
> To view this discussion on the web visit 
> https://groups.google.com/d/msgid/jenkinsci-users/2533263d-1399-46f9-9196-412f89ac7133%40googlegroups.com
>  
> <https://groups.google.com/d/msgid/jenkinsci-users/2533263d-1399-46f9-9196-412f89ac7133%40googlegroups.com?utm_medium=email&utm_source=footer>
> .
> For more options, visit https://groups.google.com/d/optout.
>
>
>

-- 
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 [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/jenkinsci-users/607cdd1c-a314-44ef-85a6-495eeb7636be%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to