AbstractBuild.java 23.3 KB
Newer Older
1 2
package hudson.model;

3
import hudson.Functions;
4 5
import hudson.Launcher;
import hudson.Util;
6
import hudson.matrix.MatrixConfiguration;
7
import hudson.maven.MavenBuild;
8 9
import hudson.model.Fingerprint.BuildPtr;
import hudson.model.Fingerprint.RangeSet;
K
kohsuke 已提交
10
import hudson.model.listeners.SCMListener;
11 12 13 14 15
import hudson.scm.CVSChangeLogParser;
import hudson.scm.ChangeLogParser;
import hudson.scm.ChangeLogSet;
import hudson.scm.ChangeLogSet.Entry;
import hudson.scm.SCM;
16
import hudson.tasks.BuildStep;
17
import hudson.tasks.BuildWrapper;
18 19
import hudson.tasks.Builder;
import hudson.tasks.Fingerprinter.FingerprintAction;
20
import hudson.tasks.Publisher;
21
import hudson.tasks.test.AbstractTestResultAction;
K
kohsuke 已提交
22
import hudson.util.AdaptedIterator;
K
kohsuke 已提交
23
import hudson.util.Iterators;
24
import org.kohsuke.stapler.Stapler;
25 26
import org.kohsuke.stapler.StaplerRequest;
import org.kohsuke.stapler.StaplerResponse;
27
import org.kohsuke.stapler.export.Exported;
28
import org.xml.sax.SAXException;
29

30
import javax.servlet.ServletException;
31 32
import java.io.File;
import java.io.IOException;
33 34 35 36 37 38 39 40 41 42 43
import java.util.AbstractSet;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Set;
K
kohsuke 已提交
44

45 46 47 48 49 50 51 52
/**
 * Base implementation of {@link Run}s that build software.
 *
 * For now this is primarily the common part of {@link Build} and {@link MavenBuild}.
 *
 * @author Kohsuke Kawaguchi
 * @see AbstractProject
 */
53
public abstract class AbstractBuild<P extends AbstractProject<P,R>,R extends AbstractBuild<P,R>> extends Run<P,R> implements Queue.Executable {
54 55

    /**
K
kohsuke 已提交
56
     * Name of the slave this project was built on.
K
kohsuke 已提交
57
     * Null or "" if built by the master. (null happens when we read old record that didn't have this information.)
58 59 60
     */
    private String builtOn;

61 62 63 64 65
    /**
     * Version of Hudson that built this.
     */
    private String hudsonVersion;

66 67 68 69 70 71 72 73 74 75 76
    /**
     * SCM used for this build.
     * Maybe null, for historical reason, in which case CVS is assumed.
     */
    private ChangeLogParser scm;

    /**
     * Changes in this build.
     */
    private volatile transient ChangeLogSet<? extends Entry> changeSet;

77 78 79 80 81 82 83 84 85 86 87 88 89 90
    /**
     * Cumulative list of people who contributed to the build problem.
     *
     * <p>
     * This is a list of {@link User#getId() user ids} who made a change
     * since the last non-broken build. Can be null (which should be
     * treated like empty set), because of the compatibility.
     *
     * <p>
     * This field is semi-final --- once set the value will never be modified.
     *
     * @since 1.137
     */
    private volatile Set<String> culprits;
K
kohsuke 已提交
91 92 93 94 95 96
    
    /**
     * During the build this field remembers {@link BuildWrapper.Environment}s created by
     * {@link BuildWrapper}. This design is bit ugly but forced due to compatibility.
     */
    protected transient List<BuildWrapper.Environment> buildEnvironments;
97

98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117
    protected AbstractBuild(P job) throws IOException {
        super(job);
    }

    protected AbstractBuild(P job, Calendar timestamp) {
        super(job, timestamp);
    }

    protected AbstractBuild(P project, File buildDir) throws IOException {
        super(project, buildDir);
    }

    public final P getProject() {
        return getParent();
    }

    /**
     * Returns a {@link Slave} on which this build was done.
     */
    public Node getBuiltOn() {
K
kohsuke 已提交
118
        if(builtOn==null || builtOn.equals(""))
119 120 121 122 123 124 125 126
            return Hudson.getInstance();
        else
            return Hudson.getInstance().getSlave(builtOn);
    }

    /**
     * Returns the name of the slave it was built on, or null if it was the master.
     */
K
kohsuke 已提交
127
    @Exported(name="builtOn")
128 129 130 131
    public String getBuiltOnStr() {
        return builtOn;
    }

K
kohsuke 已提交
132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147
    /**
     * Used to render the side panel "Back to project" link.
     *
     * <p>
     * In a rare situation where a build can be reached from multiple paths,
     * returning different URLs from this method based on situations might
     * be desirable.
     *
     * <p>
     * If you override this method, you'll most likely also want to override
     * {@link #getDisplayName()}.
     */
    public String getUpUrl() {
        return Functions.getNearestAncestorUrl(Stapler.getCurrentRequest(),getParent())+'/';
    }

148 149 150 151
    /**
     * List of users who committed a change since the last non-broken build till now.
     *
     * <p>
K
kohsuke 已提交
152 153
     * This list at least always include people who made changes in this build, but
     * if the previous build was a failure it also includes the culprit list from there.
154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188
     *
     * @return
     *      can be empty but never null.
     */
    @Exported
    public Set<User> getCulprits() {
        if(culprits==null) {
            Set<User> r = new HashSet<User>();
            if(getPreviousBuild()!=null && isBuilding() && getPreviousBuild().getResult().isWorseThan(Result.UNSTABLE)) {
                // we are still building, so this is just the current latest information,
                // but we seems to be failing so far, so inherit culprits from the previous build.
                // isBuilding() check is to avoid recursion when loading data from old Hudson, which doesn't record
                // this information
                r.addAll(getPreviousBuild().getCulprits());
            }
            for( Entry e : getChangeSet() )
                r.add(e.getAuthor());
            return r;
        }

        return new AbstractSet<User>() {
            public Iterator<User> iterator() {
                return new AdaptedIterator<String,User>(culprits.iterator()) {
                    protected User adapt(String id) {
                        return User.get(id);
                    }
                };
            }

            public int size() {
                return culprits.size();
            }
        };
    }

189 190 191 192 193 194 195 196 197 198 199 200
    /**
     * Returns true if this user has made a commit to this build.
     *
     * @since 1.191
     */
    public boolean hasParticipant(User user) {
        for (ChangeLogSet.Entry e : getChangeSet())
            if(e.getAuthor()==user)
                return true;
        return false;
    }

K
kohsuke 已提交
201 202 203 204 205 206 207 208 209
    /**
     * Gets the version of Hudson that was used to build this job.
     *
     * @since 1.246
     */
    public String getHudsonVersion() {
        return hudsonVersion;
    }

210 211 212 213 214 215 216
    protected abstract class AbstractRunner implements Runner {
        /**
         * Since configuration can be changed while a build is in progress,
         * stick to one launcher and use it.
         */
        protected Launcher launcher;

K
kohsuke 已提交
217 218 219 220 221 222 223
        /**
         * Returns the current {@link Node} on which we are buildling.
         */
        protected final Node getCurrentNode() {
            return Executor.currentExecutor().getOwner().getNode();
        }

224
        public Result run(BuildListener listener) throws Exception {
225
            Node node = getCurrentNode();
226 227
            assert builtOn==null;
            builtOn = node.getNodeName();
228
            hudsonVersion = Hudson.VERSION;
229 230 231

            launcher = node.createLauncher(listener);
            if(node instanceof Slave)
K
i18n  
kohsuke 已提交
232
                listener.getLogger().println(Messages.AbstractBuild_BuildingRemotely(node.getNodeName()));
233

234
            if(checkout(listener))
235 236
                return Result.FAILURE;

237 238 239
            if(!preBuild(listener,project.getProperties()))
                return Result.FAILURE;

240
            Result result = doRun(listener);
241 242 243 244 245 246

            // the two if statements here are a real mess.
            // the "return null to mean success" convention is not very consistent
            // so we should probably get rid of that. And in the mean time
            // this check will allows us to create symlinks
            if(result!=null && result!=Result.SUCCESS)
247 248
                return result;  // abort here

K
kohsuke 已提交
249 250
            if(getResult()==null || getResult()==Result.SUCCESS)
                createLastSuccessfulLink(listener);
251 252 253 254

            return Result.SUCCESS;
        }

255
        private void createLastSuccessfulLink(BuildListener listener) throws InterruptedException {
256
            Util.createSymlink(getProject().getBuildDir(),"builds/"+getId(),"../lastSuccessful",listener);
257
        }
258

259 260 261 262 263 264 265 266 267 268 269 270
        private boolean checkout(BuildListener listener) throws Exception {
            if(!project.checkout(AbstractBuild.this,launcher,listener,new File(getRootDir(),"changelog.xml")))
                return true;

            SCM scm = project.getScm();

            AbstractBuild.this.scm = scm.createChangeLogParser();
            AbstractBuild.this.changeSet = AbstractBuild.this.calcChangeSet();

            for (SCMListener l : Hudson.getInstance().getSCMListeners())
                l.onChangeLogParsed(AbstractBuild.this,listener,changeSet);
            return false;
271 272
        }

K
kohsuke 已提交
273 274 275 276 277 278 279 280 281
        /**
         * The portion of a build that is specific to a subclass of {@link AbstractBuild}
         * goes here.
         *
         * @return
         *      null to continue the build normally (that means the doRun method
         *      itself run successfully)
         *      Return a non-null value to abort the build right there with the specified result code.
         */
K
kohsuke 已提交
282
        protected abstract Result doRun(BuildListener listener) throws Exception, RunnerAbortedException;
283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299

        /**
         * @see #post(BuildListener)
         */
        protected abstract void post2(BuildListener listener) throws Exception;

        public final void post(BuildListener listener) throws Exception {
            try {
                post2(listener);
            } finally {
                // update the culprit list
                HashSet<String> r = new HashSet<String>();
                for (User u : getCulprits())
                    r.add(u.getId());
                culprits = r;
            }
        }
300 301 302 303

        public void cleanUp(BuildListener listener) throws Exception {
            // default is no-op
        }
304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320

        protected final void performAllBuildStep(BuildListener listener, Map<?,? extends BuildStep> buildSteps, boolean phase) throws InterruptedException, IOException {
            performAllBuildStep(listener,buildSteps.values(),phase);
        }

        /**
         * Runs all the given build steps, even if one of them fail.
         *
         * @param phase
         *      true for the post build processing, and false for the final "run after finished" execution.
         */
        protected final void performAllBuildStep(BuildListener listener, Iterable<? extends BuildStep> buildSteps, boolean phase) throws InterruptedException, IOException {
            for( BuildStep bs : buildSteps ) {
                if( (bs instanceof Publisher && ((Publisher)bs).needsToRunAfterFinalized()) ^ phase)
                    bs.perform(AbstractBuild.this, launcher, listener);
            }
        }
321 322

        protected final boolean preBuild(BuildListener listener,Map<?,? extends BuildStep> steps) {
323 324 325 326
            return preBuild(listener,steps.values());
        }

        protected final boolean preBuild(BuildListener listener,Collection<? extends BuildStep> steps) {
327 328 329 330
            return preBuild(listener,(Iterable<? extends BuildStep>)steps);
        }

        protected final boolean preBuild(BuildListener listener,Iterable<? extends BuildStep> steps) {
331
            for( BuildStep bs : steps )
332 333 334 335
                if(!bs.prebuild(AbstractBuild.this,listener))
                    return false;
            return true;
        }
336
    }
K
kohsuke 已提交
337

338 339 340 341 342
    /**
     * Gets the changes incorporated into this build.
     *
     * @return never null.
     */
K
kohsuke 已提交
343
    @Exported
344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363
    public ChangeLogSet<? extends Entry> getChangeSet() {
        if(scm==null)
            scm = new CVSChangeLogParser();

        if(changeSet==null) // cached value
            changeSet = calcChangeSet();
        return changeSet;
    }

    /**
     * Returns true if the changelog is already computed.
     */
    public boolean hasChangeSetComputed() {
        File changelogFile = new File(getRootDir(), "changelog.xml");
        return changelogFile.exists();
    }

    private ChangeLogSet<? extends Entry> calcChangeSet() {
        File changelogFile = new File(getRootDir(), "changelog.xml");
        if(!changelogFile.exists())
364
            return ChangeLogSet.createEmpty(this);
365 366 367 368 369 370 371 372

        try {
            return scm.parse(this,changelogFile);
        } catch (IOException e) {
            e.printStackTrace();
        } catch (SAXException e) {
            e.printStackTrace();
        }
373
        return ChangeLogSet.createEmpty(this);
374 375 376 377 378
    }

    @Override
    public Map<String,String> getEnvVars() {
        Map<String,String> env = super.getEnvVars();
K
kohsuke 已提交
379
        env.put("WORKSPACE", getProject().getWorkspace().getRemote());
K
kohsuke 已提交
380 381 382 383
        // servlet container may have set CLASSPATH in its launch script,
        // so don't let that inherit to the new child process.
        // see http://www.nabble.com/Run-Job-with-JDK-1.4.2-tf4468601.html
        env.put("CLASSPATH","");
384 385 386 387

        JDK jdk = project.getJDK();
        if(jdk !=null)
            jdk.buildEnvVars(env);
388
        project.getScm().buildEnvVars(this,env);
389

K
kohsuke 已提交
390 391 392 393 394
        ParametersAction parameters = getAction(ParametersAction.class);
        if (parameters != null)
            parameters.buildEnvVars(this,env);

        if(buildEnvironments!=null)
K
kohsuke 已提交
395 396
            for (BuildWrapper.Environment e : buildEnvironments)
                e.buildEnvVars(env);
K
kohsuke 已提交
397
        
398 399
        return env;
    }
K
kohsuke 已提交
400

401
    public Calendar due() {
402
        return getTimestamp();
403 404
    }

405 406 407 408 409 410 411 412 413 414 415 416 417 418 419
    /**
     * Provides additional variables and their values to {@link Builder}s.
     *
     * <p>
     * This mechanism is used by {@link MatrixConfiguration} to pass
     * the configuration values to the current build. It is up to
     * {@link Builder}s to decide whether it wants to recognize the values
     * or how to use them.
     *
     * ugly ugly hack.
     */
    public Map<String,String> getBuildVariables() {
        return Collections.emptyMap();
    }
    
420 421 422
    /**
     * Gets {@link AbstractTestResultAction} associated with this build if any.
     */
423 424 425
    public AbstractTestResultAction getTestResultAction() {
        return getAction(AbstractTestResultAction.class);
    }
426

K
kohsuke 已提交
427 428 429 430 431
    /**
     * Invoked by {@link Executor} to performs a build.
     */
    public abstract void run();

432 433 434 435 436 437 438 439 440 441
//
//
// fingerprint related stuff
//
//

    @Override
    public String getWhyKeepLog() {
        // if any of the downstream project is configured with 'keep dependency component',
        // we need to keep this log
K
kohsuke 已提交
442
        OUTER:
K
kohsuke 已提交
443 444 445
        for (AbstractProject<?,?> p : getParent().getDownstreamProjects()) {
            if(!p.isKeepDependencies()) continue;

K
kohsuke 已提交
446
            AbstractBuild<?,?> fb = p.getFirstBuild();
K
kohsuke 已提交
447 448 449
            if(fb==null)        continue; // no active record

            // is there any active build that depends on us?
K
kohsuke 已提交
450
            for(int i : getDownstreamRelationship(p).listNumbersReverse()) {
K
kohsuke 已提交
451 452 453 454 455 456
                // TODO: this is essentially a "find intersection between two sparse sequences"
                // and we should be able to do much better.

                if(i<fb.getNumber())
                    continue OUTER; // all the other records are younger than the first record, so pointless to search.

K
kohsuke 已提交
457
                AbstractBuild<?,?> b = p.getBuildByNumber(i);
K
kohsuke 已提交
458
                if(b!=null)
K
kohsuke 已提交
459
                    return Messages.AbstractBuild_KeptBecause(b);
460 461 462 463 464 465
            }
        }

        return super.getWhyKeepLog();
    }

K
kohsuke 已提交
466

467 468 469 470 471 472
    /**
     * Gets the dependency relationship from this build (as the source)
     * and that project (as the sink.)
     *
     * @return
     *      range of build numbers that represent which downstream builds are using this build.
K
kohsuke 已提交
473
     *      The range will be empty if no build of that project matches this, but it'll never be null.
474
     */
475 476 477 478 479 480 481 482 483 484 485 486 487 488 489
    public RangeSet getDownstreamRelationship(AbstractProject that) {
        RangeSet rs = new RangeSet();

        FingerprintAction f = getAction(FingerprintAction.class);
        if(f==null)     return rs;

        // look for fingerprints that point to this build as the source, and merge them all
        for (Fingerprint e : f.getFingerprints().values()) {
            BuildPtr o = e.getOriginal();
            if(o!=null && o.is(this))
                rs.add(e.getRangeSet(that));
        }

        return rs;
    }
490

K
kohsuke 已提交
491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514
    /**
     * Works like {@link #getDownstreamRelationship(AbstractProject)} but returns
     * the actual build objects, in ascending order.
     * @since 1.150
     */
    public Iterable<AbstractBuild<?,?>> getDownstreamBuilds(final AbstractProject<?,?> that) {
        final Iterable<Integer> nums = getDownstreamRelationship(that).listNumbers();

        return new Iterable<AbstractBuild<?, ?>>() {
            public Iterator<AbstractBuild<?, ?>> iterator() {
                return new Iterators.FilterIterator<AbstractBuild<?,?>>(
                        new AdaptedIterator<Integer,AbstractBuild<?,?>>(nums) {
                            protected AbstractBuild<?, ?> adapt(Integer item) {
                                return that.getBuildByNumber(item);
                            }
                        }) {
                    protected boolean filter(AbstractBuild<?,?> build) {
                        return build!=null;
                    }
                };
            }
        };
    }

515 516 517 518 519 520 521 522
    /**
     * Gets the dependency relationship from this build (as the sink)
     * and that project (as the source.)
     *
     * @return
     *      Build number of the upstream build that feed into this build,
     *      or -1 if no record is available.
     */
523 524 525 526 527 528 529 530 531
    public int getUpstreamRelationship(AbstractProject that) {
        FingerprintAction f = getAction(FingerprintAction.class);
        if(f==null)     return -1;

        int n = -1;

        // look for fingerprints that point to the given project as the source, and merge them all
        for (Fingerprint e : f.getFingerprints().values()) {
            BuildPtr o = e.getOriginal();
532
            if(o!=null && o.belongsTo(that))
533 534 535 536 537
                n = Math.max(n,o.getNumber());
        }

        return n;
    }
538

K
kohsuke 已提交
539 540 541 542 543 544 545 546
    /**
     * Works like {@link #getUpstreamRelationship(AbstractProject)} but returns the
     * actual build object.
     *
     * @return
     *      null if no such upstream build was found, or it was found but the
     *      build record is already lost.
     */
547
    public AbstractBuild<?,?> getUpstreamRelationshipBuild(AbstractProject<?,?> that) {
K
kohsuke 已提交
548
        int n = getUpstreamRelationship(that);
K
kohsuke 已提交
549
        if(n==-1)   return null;
K
kohsuke 已提交
550 551 552
        return that.getBuildByNumber(n);
    }

553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572
    /**
     * Gets the downstream builds of this build, which are the builds of the
     * downstream projects that use artifacts of this build.
     *
     * @return
     *      For each project with fingerprinting enabled, returns the range
     *      of builds (which can be empty if no build uses the artifact from this build.)
     */
    public Map<AbstractProject,RangeSet> getDownstreamBuilds() {
        Map<AbstractProject,RangeSet> r = new HashMap<AbstractProject,RangeSet>();
        for (AbstractProject p : getParent().getDownstreamProjects()) {
            if(p.isFingerprintConfigured())
                r.put(p,getDownstreamRelationship(p));
        }
        return r;
    }
    
    /**
     * Gets the upstream builds of this build, which are the builds of the
     * upstream projects whose artifacts feed into this build.
K
kohsuke 已提交
573 574
     *
     * @see #getTransitiveUpstreamBuilds()
575 576
     */
    public Map<AbstractProject,Integer> getUpstreamBuilds() {
K
kohsuke 已提交
577 578 579 580 581 582 583 584 585 586 587 588
        return _getUpstreamBuilds(getParent().getUpstreamProjects());
    }

    /**
     * Works like {@link #getUpstreamBuilds()}  but also includes all the transitive
     * dependencies as well.
     */
    public Map<AbstractProject,Integer> getTransitiveUpstreamBuilds() {
        return _getUpstreamBuilds(getParent().getTransitiveUpstreamProjects());
    }

    private Map<AbstractProject, Integer> _getUpstreamBuilds(Collection<AbstractProject> projects) {
589
        Map<AbstractProject,Integer> r = new HashMap<AbstractProject,Integer>();
K
kohsuke 已提交
590
        for (AbstractProject p : projects) {
591 592 593 594 595 596 597
            int n = getUpstreamRelationship(p);
            if(n>=0)
                r.put(p,n);
        }
        return r;
    }

598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653
    /**
     * Gets the changes in the dependency between the given build and this build.
     */
    public Map<AbstractProject,DependencyChange> getDependencyChanges(AbstractBuild from) {
        if(from==null)             return Collections.emptyMap(); // make it easy to call this from views
        FingerprintAction n = this.getAction(FingerprintAction.class);
        FingerprintAction o = from.getAction(FingerprintAction.class);
        if(n==null || o==null)     return Collections.emptyMap();

        Map<AbstractProject,Integer> ndep = n.getDependencies();
        Map<AbstractProject,Integer> odep = o.getDependencies();

        Map<AbstractProject,DependencyChange> r = new HashMap<AbstractProject,DependencyChange>();

        for (Map.Entry<AbstractProject,Integer> entry : odep.entrySet()) {
            AbstractProject p = entry.getKey();
            Integer oldNumber = entry.getValue();
            Integer newNumber = ndep.get(p);
            if(newNumber!=null && oldNumber.compareTo(newNumber)<0) {
                r.put(p,new DependencyChange(p,oldNumber,newNumber));
            }
        }

        return r;
    }

    /**
     * Represents a change in the dependency.
     */
    public static final class DependencyChange {
        /**
         * The dependency project.
         */
        public final AbstractProject project;
        /**
         * Version of the dependency project used in the previous build.
         */
        public final int fromId;
        /**
         * {@link Build} object for {@link #fromId}. Can be null if the log is gone.
         */
        public final AbstractBuild from;
        /**
         * Version of the dependency project used in this build.
         */
        public final int toId;

        public final AbstractBuild to;

        public DependencyChange(AbstractProject<?,?> project, int fromId, int toId) {
            this.project = project;
            this.fromId = fromId;
            this.toId = toId;
            this.from = project.getBuildByNumber(fromId);
            this.to = project.getBuildByNumber(toId);
        }
654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674

        /**
         * Gets the {@link AbstractBuild} objects (fromId,toId].
         * <p>
         * This method returns all such available builds in the ascending order
         * of IDs, but due to log rotations, some builds may be already unavailable. 
         */
        public List<AbstractBuild> getBuilds() {
            List<AbstractBuild> r = new ArrayList<AbstractBuild>();

            AbstractBuild<?,?> b = (AbstractBuild)project.getNearestBuild(fromId);
            if(b!=null && b.getNumber()==fromId)
                b = b.getNextBuild(); // fromId exclusive

            while(b!=null && b.getNumber()<=toId) {
                r.add(b);
                b = b.getNextBuild();
            }

            return r;
        }
675
    }
676

677 678 679 680 681
//
//
// web methods
//
//
K
kohsuke 已提交
682 683 684 685 686 687 688 689 690 691 692 693 694 695
    /**
     * Stops this build if it's still going.
     *
     * If we use this/executor/stop URL, it causes 404 if the build is already killed,
     * as {@link #getExecutor()} returns null.
     */
    public synchronized void doStop( StaplerRequest req, StaplerResponse rsp ) throws IOException, ServletException {
        Executor e = getExecutor();
        if(e!=null)
            e.doStop(req,rsp);
        else
            // nothing is building
            rsp.forwardToPreviousPage(req);
    }
696
}