All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.jvnet.hudson.test.FailureBuilder Maven / Gradle / Ivy

The newest version!
/*******************************************************************************
 *
 * Copyright (c) 2004-2009 Oracle Corporation.
 *
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors:
 * 
 *    Kohsuke Kawaguchi
 *
 *
 *******************************************************************************/ 

package org.jvnet.hudson.test;

import hudson.Launcher;
import hudson.Extension;
import hudson.model.AbstractBuild;
import hudson.model.BuildListener;
import hudson.model.Descriptor;
import hudson.model.Result;
import hudson.tasks.Builder;
import net.sf.json.JSONObject;
import org.kohsuke.stapler.StaplerRequest;

import java.io.IOException;

/**
 * Mock {@link Builder} that always cause a build to fail.
 *
 * @author Kohsuke Kawaguchi
 */
public class FailureBuilder extends Builder {

    public boolean perform(AbstractBuild build, Launcher launcher, BuildListener listener) throws InterruptedException, IOException {
        listener.getLogger().println("Simulating a failure");
        build.setResult(Result.FAILURE);
        return false;
    }

    @Extension
    public static final class DescriptorImpl extends Descriptor {

        public String getDisplayName() {
            return "Always fail";
        }

        public FailureBuilder newInstance(StaplerRequest req, JSONObject data) {
            return new FailureBuilder();
        }
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy