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

4

66

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

Honorific answered 30/3, 2011 at 13:39 Comment(0)
C
82

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

Cesta answered 18/4, 2011 at 10:42 Comment(3)
THANK YOU! This is the option I was looking for but is not explicitly mentioned on the plugin's page.Nevels
The docs do mention "usage as a build step", although you need to realize this is what you need, which isn't immediately obvious, certainly not from the plugin name.Solis
Just an addition that "Trigger/Call build on other project" section should be first and then use other containers like "Execute windows batch command"Cornwell
S
10

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.

Selfappointed answered 30/3, 2011 at 15:16 Comment(2)
Thanks Sagar!! This "bad part" is exactly what I was looking for. But how this Rest API deals with authentication? Because my Jenkins is configure to request login before any action.Invariant
@NaderA.Jabbar The Jenkins ReST API actually supports authentication with Authentication tokens. You could use a per-job token, or your own authentication API token, from scripts. Check out the URL http://yourserver/hudson/job/MyJob/api for more information for calling builds using the API. Also, under "Perform a build", there are two links. Check the one for calling a build with parameters.Selfappointed
R
2

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.

Riven answered 26/1, 2012 at 9:41 Comment(2)
you can use the old version of Jenkins that supports thatRiven
This was written a year ago, of course is not a lively suggestion, but it's a solution.Riven
Q
0

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.

Quorum answered 26/3, 2012 at 15:2 Comment(1)
I'm having same thing to do in my project,i'm using the Jenkins ver. 1.479, I enable following in job configuration "Build Triggers->Build after other projects are built", but this is not work for me (not execute the the dependent project also i want to know how to pass parameters to depended project)Prophylactic

© 2022 - 2024 — McMap. All rights reserved.