64
votes

How do I trigger another job from hudson as a pre-build step?

4

4 Answers

81
votes

There is a Parameterized Trigger Plugin, which enables "Trigger/call builds on other projects" in "Add build step" menu.

10
votes

You can use the plugin at http://wiki.jenkins-ci.org/display/JENKINS/Join+Plugin

Basically you create 3 jobs:

A = your prebuild ste

B = your main job

C = your trigger.

You 'build' C. It calls A, and once A is successful, it calls B. The plugin page gives you more information. The good thing about this plugin is that you can have any number of pre-build jobs.

We actually have a set of 5 pre-build jobs before our main is run.

================================================

If you don't want to try that:

If you are using Linux, you can do the following from within your "shell" script:

wget http://yourserver/hudson/job/MyJob/build?delay=0sec

This will trigger the job. The bad part about this is that it will not wait for the job to finish.

1
votes

Actually I know how to answer to your question: This is the plug-in that you need:

PreBuild

It is not widely famous, but it does what you want.

It basically runs a Build before your chosen one. For example: You want A to run before B. You click on "run B" it will execute A before running B.

Pro: -> Very versatile -> Easy to use

Cons: -> No support / Option in case the pre-build fails (e.g. do not build if pre-build fails) -> The development seems not being that active at all.

Here you can see how it looks like enter image description here

EDIT

This answer is back from '12, I know you are down-voting it, but back then this was a reliable solution, now I am sure there are other plug-ins that do the job.

0
votes

I have the same issue and I found a way to do:

I am using jenkins version jenkins-1.452-1.1.

Say I have job A and B, and Job A is depending on job B. When building job B, I want A triggered automatically, and B is blocked until A build successfully.

When define build configuration in build section, I add 'trigger build on other projects'. then fill the form.