How to get the subprojects of a certain freestyleproject

313 views
Skip to first unread message

李军

unread,
Apr 22, 2013, 5:15:01 AM4/22/13
to jenkins...@googlegroups.com
Hello guys,

I am pretty new to jenkins. I have encountered a problem and need your kind help :p

I have setup a project, lets say project A. This project contains a certain project B as part of it(via "trigger/call builds on other projects" with "Block until the triggered projects finish their builds" option checked).
I would like to fail the ongoing run of project B when I hit the little cancel button(<server>/job/#projectA#/#run#/stop) of project A. I browsed the job configuration page but found no solution.

So my question is:

1) is there sort of hudson api(like cancel event listener) I can use to compose a groovy script and do the job gracefully?
2) how shall I get the subprojects of a job programmatically? I have checked the getSubTasks method(http://javadoc.jenkins-ci.org/hudson/model/AbstractProject.html#getSubTasks()) but failed.

Thanks


Dmitry Sobol

unread,
Sep 24, 2015, 12:35:28 PM9/24/15
to Jenkins Users
Hi,  there is groovy script as answer

def subProjects = new ArrayList()
def triggersBuilder = build.getProject().getBuilders()

triggersBuilder.each { trigger ->
        if(trigger instanceof hudson.plugins.parameterizedtrigger.TriggerBuilder) {
                def blockableBuildTriggerConfigs = trigger.getConfigs()
                blockableBuildTriggerConfigs.each { config ->
                        if(config.getBlock() != null) {
                                subProjects.add(config.getProjectList(null))
                        }
                }

        }
}


subProjects.each { project -> println(project) }


Reply all
Reply to author
Forward
0 new messages