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

hudson.tasks.BatchFile Maven / Gradle / Ivy

The newest version!
/*******************************************************************************
 *
 * Copyright (c) 2004-2010 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 hudson.tasks;

import hudson.Extension;
import hudson.FilePath;
import hudson.model.AbstractProject;
import net.sf.json.JSONObject;
import org.kohsuke.stapler.DataBoundConstructor;
import org.kohsuke.stapler.StaplerRequest;

/**
 * Executes commands by using Windows batch file.
 *
 * @author Kohsuke Kawaguchi
 */
public class BatchFile extends CommandInterpreter {
    
     public BatchFile(String command) {
         this(command, false, "");
     }

    @DataBoundConstructor
    public BatchFile(String command, boolean disabled, String description) {
        super(command);
        setDisabled(disabled);
        setDescription(description);
    }

    public String[] buildCommandLine(FilePath script) {
        return new String[]{"cmd", "/c", "call", script.getRemote()};
    }

    protected String getContents() {
        return command + "\r\nexit %ERRORLEVEL%";
    }

    protected String getFileExtension() {
        return ".bat";
    }

    @Extension
    public static final class DescriptorImpl extends BuildStepDescriptor {

        @Override
        public String getHelpFile() {
            return "/help/project-config/batch.html";
        }

        public String getDisplayName() {
            return Messages.BatchFile_DisplayName();
        }

        @Override
        public Builder newInstance(StaplerRequest req, JSONObject data) {
            return new BatchFile(data.getString("command"), data.getBoolean("disabled"), data.getString("description"));
        }

        public boolean isApplicable(Class jobType) {
            return true;
        }
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy