Build Cause Run condition to select whether to execute a build step or publisher. Used by the Run Condition Plugin.

{jenkins-plugin-info:pluginId=build-cause-run-condition|jiraComponent=build-cause-run-condition|sourceDir=build-cause-run-condition-plugin}

Features

This plugin implements a build cause run condition to be used by the Run Condition Plugin.

Build Cause Condition

This provides an ExtensionPoint that can be used by plugins to define new extended causes, for example this should be done for any trigger that provides its Cause type that make provide extra information that can be used.

Implemented:

For example:
Can be used to ignore all build requests from a particular user if they are abusing the build now button.

For example:
This allows configurations to perform different actions based which upstream job started this one, this will allow you to collect artefacts from just that upstream project rather than all of them.

Other Cause Conditions are currently implemented in other plugins

If your plugin is not shown here and you have implemented the BuildCauseCondition Extension point, add the label "plugin-build-cause-run-condition-provider" to the wiki page.

Implementing you own build cause condition

This requires at minimum just three items
Class extending BuildCauseCondition and providing its Descriptor extending BuildCauseConditionDescriptor


package org.jenkins-ci.plugins.exampletrigger;

public static class ExampleCauseCondition extends BuildCauseCondition {

    @DataBoundConstructor
    public ExampleCauseCondition() {
    }

    /**
     * Performs the check of the condition
     *
     * @return true if the condition is allowed
     *         false if not allowed to proceed.
     */
    public boolean runPerform(final AbstractBuild<?, ?> build, final BuildListener listener) throws InterruptedException {
        List<Cause> buildCauses = build.getRootBuild().getCauses();

        for (Cause cause : buildCauses) {
            if (Cause.ExampleCause.class.isInstance(cause)) {
								return true;
             }
        }
        return false;
    }

    @Extension
    public static class ExampleCauseConditionDescriptor extends BuildCauseConditionDescriptor {

        @Override
        public String getDisplayName() {
            return "Example Cause"
        }
        
    }
}

and also a config.jelly file to display it.


<?jelly escape-by-default='true'?>
<j:jelly xmlns:j="jelly:core" xmlns:f="/lib/form" />

For other examples see the implementations of UserCause and UpstreamCause in the plugin on github.

Change log

0.1 (25/7/2012)

Please post questions or comments about this plugin to the Jenkins User mailing list.
To report a bug or request an enhancement to this plugin please create a ticket in JIRA.