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

hudson.Main Maven / Gradle / Ivy

package hudson;

import hudson.model.ExternalJob;
import hudson.model.ExternalRun;
import hudson.model.Hudson;
import hudson.model.Job;
import hudson.model.Result;
import hudson.util.DualOutputStream;
import hudson.util.EncodingStream;

import java.io.File;
import java.io.OutputStream;
import java.io.OutputStreamWriter;
import java.io.Writer;
import java.net.HttpURLConnection;
import java.net.URL;
import java.net.URLEncoder;
import java.util.ArrayList;
import java.util.List;

/**
 * Entry point to Hudson from command line.
 *
 * @author Kohsuke Kawaguchi
 */
public class Main {
    public static void main(String[] args) {
        try {
            System.exit(run(args));
        } catch (Exception e) {
            e.printStackTrace();
            System.exit(-1);
        }
    }

    public static int run(String[] args) throws Exception {
        String home = getHudsonHome();
        if(home==null) {
            System.err.println("HUDSON_HOME is not set.");
            return -1;
        }

        if(home.startsWith("http")) {
            return remotePost(args);
        } else {
            return localPost(args);
        }
    }

    private static String getHudsonHome() {
        return EnvVars.masterEnvVars.get("HUDSON_HOME");
    }

    /**
     * Run command and place the result directly into the local installation of Hudson.
     */
    public static int localPost(String[] args) throws Exception {
        Hudson app = new Hudson(new File(getHudsonHome()),null);

        Job job = app.getJob(args[0]);
        if(!(job instanceof ExternalJob)) {
            System.err.println(args[0]+" is not a valid external job name in Hudson");
            return -1;
        }
        ExternalJob ejob = (ExternalJob) job;

        ExternalRun run = ejob.newBuild();

        // run the command
        List cmd = new ArrayList();
        for( int i=1; i");
        w.write("");
        w.flush();

        // run the command
        long start = System.currentTimeMillis();

        List cmd = new ArrayList();
        for( int i=1; i"+ret+""+(System.currentTimeMillis()-start)+"");
        w.close();

        if(con.getResponseCode()!=200) {
            Util.copyStream(con.getErrorStream(),System.err);
        }

        return ret;
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy