views:

100

answers:

2

Is there a way to run all jobs in one hudson's view by pressing just one button? Thanks.

A: 

You could define a parent Job and use it to launch all the children job (maven jobs with a dependency tree).

Combined with the Join Plugin, you can even set a Job when all previous jobs are completed.

VonC
Dependencies are the only way I can think off, too. Otherwise check your jobs if they can be triggered by an SCM change or to run them periodically (like once a day).
Peter Schuetze
+1  A: 

Update: here is the solution

Edit your view's description and paste this code into it:

<script type="text/javascript">
<!--
function triggerBuilds(obj){
    obj.responseText.evalJSON()['jobs'].each(
            function(i){
                new Ajax.Request(i['url']+'build',{method:'GET'});
            }
    );
}

function buildAll(){
    new Ajax.Request(
            document.URL.replace(/[\W]+$/,'') + '/api/json',
            {
                onSuccess : triggerBuilds,
                method : 'GET'
            }
    );
}

//-->
</script>
<a href="javascript:buildAll();void(0)">Build all Jobs in this view</a>

This will create a link that builds all jobs in the current view using hudson's JSON api. (Only works from the view, if you want to use it from somewhere else you have to change the relative URLs).

(this solution relies on prototype which is present in current versions of hudson, but I don't know how long it has been present, so this may not work for older versions)

or create a bookmarklet for this URL:

javascript:var%20f=function(obj){obj.responseText.evalJSON()['jobs'].each(function(i){new%20Ajax.Request(i['url']+'build',{method:'GET'});});};new%20Ajax.Request(document.URL.replace(/[\W]+$/,'')+'/api/json',{onSuccess:f,method:'GET'});void(0)

in your bookmark menu and execute it on any hudson view you like


Edit: I have elaborated on this answer on my weblog.

seanizer
sorry, it doesn't work for me.
Varyanica
could you please elaborate? what browser, what error message do you get, if any? (for me it works fine in firefox, ie and safari on several different views in several different hudson installations)
seanizer
we use chrome and firefox. it doesnt give me any error messages.
Varyanica
do you have the rights to execute the hudson api? (try `http://yourhudson/view/yourview/api` ). Is the url of the view of the form `http://yourhudson/view/yourview/` ? Is javascript turned on?
seanizer
javascript is turned on. my urls look like http://pc:8080/view/All/
Varyanica
Hudson's version is ver. 1.354. Maybe we should update it.
Varyanica
don't think that's it, I am using 1.355 on one machine where it works, and both the api and prototype have been in hudson for ages. Try the debug version from my edited post. Do you see anything?
seanizer
I get this:Job started: bond_ua_win_together_ua_emailJob started: bond_ua_win_together_ua_friendsJob started: bond_ua_win_together_ua_kladrbut actually jobs dont start
Varyanica
when i hit urls in response it gives me error because urls there represented as IP.
Varyanica
i get it to work. thank you!
Varyanica
Cool, you're welcome
seanizer