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;
}
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;
}
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());
}
}
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;
}
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;
}
Aggregations