21

If I understand correctly I can make a build step conditional using this plugin: https://wiki.jenkins-ci.org/display/JENKINS/Conditional+BuildStep+Plugin

First does this plugin work the Post-Build steps? Second is there a way to make Post-Build steps conditional without a plugin?

The scenario I have is I am supporting both WebDriver and Selenium IDE tests with one universal Jenkins Job setup. If they have checked in either type of test it runs them. I then want it to conditionally look if any results files show up and if so then do the publish results Post-Build step, otherwise skip that step.

Currently if no results show up it simply marks the build as a failure since no test results were found.

Any suggestions would help!

John
  • 286
  • 1
  • 2
  • 9

2 Answers2

30

You can make any Build step execute as Post-build step.

  • Install Flexible Publish plugin
  • Install Any Build Step plugin
  • Under Configure System, look for "Flexible publish", and choose Any build step from drop-down.

The configure Job.

  • In your Job configuration, add Post-build action called "Flexible Publish".
  • Select condition.
  • Select action.
Slav
  • 27,057
  • 11
  • 80
  • 104
  • 1
    So I assume without using these plugins there is no way to accomplish this? – John Oct 29 '14 at 21:09
  • 3
    You can manually script any action you want with whatever conditions you choose, in shell, batch, or even groovy... but even then... you'd still need a plugin to execute the said script in post-build actions. Jenkins is that type of software that just isn't worth it without plugins. – Slav Oct 30 '14 at 13:15
  • Thanks, I was just trying to accomplish this with the least amount of add-ons, but I agree with what you said that it doesn't seem worth it to avoid those extra plugins. – John Oct 30 '14 at 15:30
  • Even with the plugins, what @Slav said is the opposite of John and I want. I want the Conditional step can use the post-build actions which currently is not included. Using Conditional plugin, only build actions can be used. – Jirong Hu Mar 16 '16 at 20:16
  • 2
    Just to correct myself, these plugin can be used for post-build actions too. – Jirong Hu Mar 17 '16 at 19:02
  • WARNING: (After trying this method) The flexible publish, in some circumstances, will cause your builds to wait for previous triggered builds (https://issues.jenkins-ci.org/browse/JENKINS-31410). – Dan Mordechai Jul 16 '18 at 14:35
  • 1
    This is not applicable to Pipeline builds. So, there is no need to install these two plug-ins (that requires tens of others) to find out it is not possible in that case. – Phil Nov 07 '20 at 17:25
1

It is posssible but it is a bit messy and can not be done with ui only.

Create the the conditional build step in the build block and save the konfiguration. Edit the xml file and move the whole conditional build step it to the post build block. Reload the jenkins configuration and it works like intended.

Frankenstein
  • 653
  • 9
  • 18