24

I have two jobs:

  1. Upload
  2. Launch-instance

I want to make Launch-instance dependent on the other one, so that triggering Launch-instance automatically causes Upload to be run first.

Can I achieve this using built-in Jenkins features or with a plugin?

Note that I do not want Upload to always trigger Launch-instance, which is what the "Build after other projects are built" option on Launch-instance would do. What I want is more analogous to how depends attribute works in Ant.

Jonik
  • 80,077
  • 70
  • 264
  • 372

5 Answers5

28

Have you tried the Parametrized Trigger Plugin?

You can use it as a build step, and mark the checkbox for "Block until the triggered projects finish their builds". That should be exactly what you are looking for.

pushy
  • 9,535
  • 5
  • 26
  • 45
  • Thanks! I don't have the time (or need) to try out the plugin right now, but yes, this looks like a good way to do it. – Jonik Sep 21 '11 at 09:22
  • I have installed this plugin but the option to "Trigger/call builds on other projects" from the "Build Steps" menu is not there. – John Sep 04 '12 at 16:19
6

Aha, found it! Here I'm building on miki's answer which showed the way but didn't fully solve this for me.

As it says in the Spanish-language article about launching Hudson builds which was linked to from the comments of Hudson's Remote access API page that miki linked to:

En la sección "Build Triggers" [...] marcamos la opción "Trigger builds remotely (e.g., from scripts)". Al marcar esta opción vemos como aparece el cuadro de texto "Authentication Token". Aquí pondremos el nombre del token de autenticación.

alt text
(source: adictosaltrabajo.com)

(It seems the benefits of knowing Spanish are starting to materialise... :-)

So, turns out Hudson provides a handy built-in option for triggering builds remotely. In Build Triggers section (of Upload job in my case) you can enable remote builds and set an auth token (see screenshot above). Then you can launch a build by accessing a certain URL containing that token. In my case, the first build step of Launch-instance looks like:

wget http://[hudson-url]/job/Upload/build?token=TEST
sleep 10

This works even if anonymous builds are disabled and simply trying to access the build URL would yield "403 Forbidden".

Glorfindel
  • 21,988
  • 13
  • 81
  • 109
Jonik
  • 80,077
  • 70
  • 264
  • 372
2

What about building Upload by calling its build URL with wget as the first build step? Then adding the beef build steps of Launch-instance.

Or for a fancier approach, perhaps use the Remote access API.

miki
  • 309
  • 2
  • 7
  • +1 for leading me to the right path! Simply accessing build URL won't work in our case as anonymous builds are disabled. But I found key advice from the link Alejandro Pérez García posted in the *comments* of that "Remote access API" page. :-) I put details in separate answer: http://stackoverflow.com/questions/2674468/making-hudson-job-depend-on-another-job/2675178#2675178 – Jonik Apr 20 '10 at 12:55
  • I guess it's fairest to accept this answer. (Just remember to check out *Build Triggers -> Trigger builds remotely* in job configuration when security is enabled; details in my answer.) – Jonik Apr 26 '10 at 08:52
  • This seems like a pretty bad idea and I wouldn't suggest this solution for other users, although it does work. Other solutions below have more votes. – slacy Dec 06 '11 at 19:00
2

Running dependent job via wget is not a general solution. Since jobs are run asynchornnously your Launch-job will not be hang and wait for Upload job for a completion. using sleep is just a dirty hack and is not an option for most cases... IMHO the best solution is to use: http://wiki.jenkins-ci.org/display/JENKINS/Join+Plugin

user62058
  • 1,417
  • 2
  • 13
  • 22
0

You can use the downstream or upstream dependencies. You should use "Build Triggers" -> Build after other projects are built and/or post-build actions in the configure part of the project.

khmarbaise
  • 92,914
  • 28
  • 189
  • 235
  • You have to add "Build-Trigger"-> Build after in the "Update" project and enter "Launch-instance" there. – khmarbaise Apr 20 '10 at 11:36
  • 5
    Sorry, you didn't seem to read the whole question... It says I do **not** want *Upload* to always trigger *Launch-instance* (but when *Launch-instance* is run, *Upload* should be run first). – Jonik Apr 20 '10 at 12:15