public boolean perform()

in core/src/main/java/hudson/tasks/CommandInterpreter.java [106:181]


    public boolean perform(AbstractBuild<?,?> build, Launcher launcher, TaskListener listener) throws InterruptedException {
        FilePath ws = build.getWorkspace();
        if (ws == null) {
            Node node = build.getBuiltOn();
            if (node == null) {
                throw new NullPointerException("no such build node: " + build.getBuiltOnStr());
            }
            throw new NullPointerException("no workspace from node " + node + " which is computer " + node.toComputer() + " and has channel " + node.getChannel());
        }
        FilePath script=null;
        int r = -1;
        try {
            try {
                script = createScriptFile(ws);
            } catch (IOException e) {
                Util.displayIOException(e,listener);
                Functions.printStackTrace(e, listener.fatalError(Messages.CommandInterpreter_UnableToProduceScript()));
                return false;
            }

            try {
                EnvVars envVars = build.getEnvironment(listener);
                // on Windows environment variables are converted to all upper case,
                // but no such conversions are done on Unix, so to make this cross-platform,
                // convert variables to all upper cases.
                for(Map.Entry<String,String> e : build.getBuildVariables().entrySet())
                    envVars.put(e.getKey(),e.getValue());

                launcher.prepareFilterRules(build, this);

                Launcher.ProcStarter procStarter = launcher.launch();
                procStarter.cmds(buildCommandLine(script))
                        .envs(envVars)
                        .stdout(listener)
                        .pwd(ws);

                try {
                    Proc proc = procStarter.start();
                    r = join(proc);
                } catch (EnvVarsFilterException se) {
                    LOGGER.log(Level.FINE, "Environment variable filtering failed", se);
                    return false;
                }

                if(isErrorlevelForUnstableBuild(r)) {
                    build.setResult(Result.UNSTABLE);
                    r = 0;
                }
            } catch (IOException e) {
                Util.displayIOException(e, listener);
                Functions.printStackTrace(e, listener.fatalError(Messages.CommandInterpreter_CommandFailed()));
            }
            return r==0;
        } finally {
            try {
                if(script!=null)
                    script.delete();
            } catch (IOException e) {
                if (r==-1 && e.getCause() instanceof ChannelClosedException) {
                    // JENKINS-5073
                    // r==-1 only when the execution of the command resulted in IOException,
                    // and we've already reported that error. A common error there is channel
                    // losing a connection, and in that case we don't want to confuse users
                    // by reporting the 2nd problem. Technically the 1st exception may not be
                    // a channel closed error, but that's rare enough, and JENKINS-5073 is common enough
                    // that this suppressing of the error would be justified
                    LOGGER.log(Level.FINE, "Script deletion failed", e);
                } else {
                    Util.displayIOException(e,listener);
                    Functions.printStackTrace(e, listener.fatalError(Messages.CommandInterpreter_UnableToDelete(script)));
                }
            } catch (Exception e) {
                Functions.printStackTrace(e, listener.fatalError(Messages.CommandInterpreter_UnableToDelete(script)));
            }
        }
    }