Search in sources :

Example 1 with AbstractBuild

use of hudson.model.AbstractBuild in project hudson-2.x by hudson.

the class BuildCommand method run.

protected int run() throws Exception {
    job.checkPermission(Item.BUILD);
    ParametersAction a = null;
    if (!parameters.isEmpty()) {
        ParametersDefinitionProperty pdp = job.getProperty(ParametersDefinitionProperty.class);
        if (pdp == null)
            throw new AbortException(job.getFullDisplayName() + " is not parameterized but the -p option was specified");
        List<ParameterValue> values = new ArrayList<ParameterValue>();
        for (Entry<String, String> e : parameters.entrySet()) {
            String name = e.getKey();
            ParameterDefinition pd = pdp.getParameterDefinition(name);
            if (pd == null)
                throw new AbortException(String.format("\'%s\' is not a valid parameter. Did you mean %s?", name, EditDistance.findNearest(name, pdp.getParameterDefinitionNames())));
            values.add(pd.createValue(this, e.getValue()));
        }
        for (ParameterDefinition pd : pdp.getParameterDefinitions()) {
            if (parameters.get(pd.getName()) == null) {
                values.add(pd.getDefaultParameterValue());
            }
        }
        a = new ParametersAction(values);
    }
    Future<? extends AbstractBuild> f = job.scheduleBuild2(0, new CLICause(), a);
    if (!sync)
        return 0;
    // wait for the completion
    AbstractBuild b = f.get();
    stdout.println("Completed " + b.getFullDisplayName() + " : " + b.getResult());
    return b.getResult().ordinal;
}
Also used : ParametersDefinitionProperty(hudson.model.ParametersDefinitionProperty) ParameterValue(hudson.model.ParameterValue) AbstractBuild(hudson.model.AbstractBuild) ArrayList(java.util.ArrayList) ParametersAction(hudson.model.ParametersAction) AbortException(hudson.AbortException) ParameterDefinition(hudson.model.ParameterDefinition)

Example 2 with AbstractBuild

use of hudson.model.AbstractBuild in project hudson-2.x by hudson.

the class ListChangesCommand method act.

@Override
protected int act(List<AbstractBuild<?, ?>> builds) throws IOException {
    // No other permission check needed.
    switch(format) {
        case XML:
            PrintWriter w = new PrintWriter(stdout);
            w.println("<changes>");
            for (AbstractBuild build : builds) {
                w.println("<build number='" + build.getNumber() + "'>");
                ChangeLogSet<?> cs = build.getChangeSet();
                Model p = new ModelBuilder().get(cs.getClass());
                p.writeTo(cs, Flavor.XML.createDataWriter(cs, w));
                w.println("</build>");
            }
            w.println("</changes>");
            w.flush();
            break;
        case CSV:
            for (AbstractBuild build : builds) {
                ChangeLogSet<?> cs = build.getChangeSet();
                for (Entry e : cs) {
                    stdout.printf("%s,%s\n", QuotedStringTokenizer.quote(e.getAuthor().getId()), QuotedStringTokenizer.quote(e.getMsg()));
                }
            }
            break;
        case PLAIN:
            for (AbstractBuild build : builds) {
                ChangeLogSet<?> cs = build.getChangeSet();
                for (Entry e : cs) {
                    stdout.printf("%s\t%s\n", e.getAuthor(), e.getMsg());
                    for (String p : e.getAffectedPaths()) stdout.println("  " + p);
                }
            }
            break;
    }
    return 0;
}
Also used : ModelBuilder(org.kohsuke.stapler.export.ModelBuilder) Entry(hudson.scm.ChangeLogSet.Entry) AbstractBuild(hudson.model.AbstractBuild) Model(org.kohsuke.stapler.export.Model) PrintWriter(java.io.PrintWriter)

Example 3 with AbstractBuild

use of hudson.model.AbstractBuild in project hudson-2.x by hudson.

the class Fingerprinter method record.

private void record(AbstractBuild<?, ?> build, BuildListener listener, Map<String, String> record, final String targets) throws IOException, InterruptedException {
    final class Record implements Serializable {

        final boolean produced;

        final String relativePath;

        final String fileName;

        final String md5sum;

        public Record(boolean produced, String relativePath, String fileName, String md5sum) {
            this.produced = produced;
            this.relativePath = relativePath;
            this.fileName = fileName;
            this.md5sum = md5sum;
        }

        Fingerprint addRecord(AbstractBuild build) throws IOException {
            FingerprintMap map = Hudson.getInstance().getFingerprintMap();
            return map.getOrCreate(produced ? build : null, fileName, md5sum);
        }

        private static final long serialVersionUID = 1L;
    }
    final long buildTimestamp = build.getTimeInMillis();
    FilePath ws = build.getWorkspace();
    if (ws == null) {
        listener.error(Messages.Fingerprinter_NoWorkspace());
        build.setResult(Result.FAILURE);
        return;
    }
    List<Record> records = ws.act(new FileCallable<List<Record>>() {

        public List<Record> invoke(File baseDir, VirtualChannel channel) throws IOException {
            List<Record> results = new ArrayList<Record>();
            FileSet src = Util.createFileSet(baseDir, targets);
            DirectoryScanner ds = src.getDirectoryScanner();
            for (String f : ds.getIncludedFiles()) {
                File file = new File(baseDir, f);
                // consider the file to be produced by this build only if the timestamp
                // is newer than when the build has started.
                // 2000ms is an error margin since since VFAT only retains timestamp at 2sec precision
                boolean produced = buildTimestamp <= file.lastModified() + 2000;
                try {
                    results.add(new Record(produced, f, file.getName(), new FilePath(file).digest()));
                } catch (IOException e) {
                    throw new IOException2(Messages.Fingerprinter_DigestFailed(file), e);
                } catch (InterruptedException e) {
                    throw new IOException2(Messages.Fingerprinter_Aborted(), e);
                }
            }
            return results;
        }
    });
    for (Record r : records) {
        Fingerprint fp = r.addRecord(build);
        if (fp == null) {
            listener.error(Messages.Fingerprinter_FailedFor(r.relativePath));
            continue;
        }
        fp.add(build);
        record.put(r.relativePath, fp.getHashString());
    }
}
Also used : FilePath(hudson.FilePath) Serializable(java.io.Serializable) Fingerprint(hudson.model.Fingerprint) AbstractBuild(hudson.model.AbstractBuild) FileSet(org.apache.tools.ant.types.FileSet) VirtualChannel(hudson.remoting.VirtualChannel) IOException(java.io.IOException) FingerprintMap(hudson.model.FingerprintMap) DirectoryScanner(org.apache.tools.ant.DirectoryScanner) ArrayList(java.util.ArrayList) List(java.util.List) File(java.io.File) IOException2(hudson.util.IOException2)

Example 4 with AbstractBuild

use of hudson.model.AbstractBuild in project hudson-2.x by hudson.

the class MatrixConfiguration method getNextBuildNumber.

/**
     * Build numbers are always synchronized with the parent.
     *
     * <p>
     * Computing this is bit tricky. Several considerations:
     *
     * <ol>
     * <li>A new configuration build #N is started while the parent build #N is building,
     *     and when that happens we want to return N.
     * <li>But the configuration build #N is done before the parent build #N finishes,
     *     and when that happens we want to return N+1 because that's going to be the next one.
     * <li>Configuration builds might skip some numbers if the parent build is aborted
     *     before this configuration is built.
     * <li>If nothing is building right now and the last build of the parent is #N,
     *     then we want to return N+1.
     * </ol>
     */
@Override
public int getNextBuildNumber() {
    AbstractBuild lb = getParent().getLastBuild();
    if (lb == null)
        return 0;
    int n = lb.getNumber();
    if (!lb.isBuilding())
        n++;
    lb = getLastBuild();
    if (lb != null)
        n = Math.max(n, lb.getNumber() + 1);
    return n;
}
Also used : AbstractBuild(hudson.model.AbstractBuild)

Example 5 with AbstractBuild

use of hudson.model.AbstractBuild in project hudson-2.x by hudson.

the class DeleteBuildsCommand method act.

@Override
protected int act(List<AbstractBuild<?, ?>> builds) throws IOException {
    job.checkPermission(Run.DELETE);
    for (AbstractBuild build : builds) build.delete();
    stdout.println("Deleted " + builds.size() + " builds");
    return 0;
}
Also used : AbstractBuild(hudson.model.AbstractBuild)

Aggregations

AbstractBuild (hudson.model.AbstractBuild)8 AbstractProject (hudson.model.AbstractProject)2 Result (hudson.model.Result)2 ArrayList (java.util.ArrayList)2 AbortException (hudson.AbortException)1 EnvVars (hudson.EnvVars)1 FilePath (hudson.FilePath)1 PermalinkList (hudson.PermalinkList)1 WorkspaceSnapshot (hudson.WorkspaceSnapshot)1 Fingerprint (hudson.model.Fingerprint)1 FingerprintMap (hudson.model.FingerprintMap)1 Hudson (hudson.model.Hudson)1 ParameterDefinition (hudson.model.ParameterDefinition)1 ParameterValue (hudson.model.ParameterValue)1 ParametersAction (hudson.model.ParametersAction)1 ParametersDefinitionProperty (hudson.model.ParametersDefinitionProperty)1 Permalink (hudson.model.PermalinkProjectAction.Permalink)1 PromotionBadge (hudson.plugins.promoted_builds.PromotionBadge)1 VirtualChannel (hudson.remoting.VirtualChannel)1 Entry (hudson.scm.ChangeLogSet.Entry)1