void onLoad(@Nonnull Job<?,?> job, int buildNumber) { Run<?,?> build = job.getBuildByNumber(buildNumber); if (build != null) { onLoad(build); } }
/** * Gets the {@link Job} that this pointer points to, * or null if such a job no longer exists. */ public Run getRun() { Job j = getJob(); if(j==null) return null; return j.getBuildByNumber(number); }
public void find(String token, List<SearchItem> result) { try { if (token.startsWith("#")) token = token.substring(1); // ignore leading '#' int n = Integer.parseInt(token); Run b = getBuildByNumber(n); if (b == null) return; // no such build result.add(SearchItems.create("#" + n, "" + n, b)); } catch (NumberFormatException e) { // not a number. } }
@Override public Object fromString(String string) { String[] split = string.split("#"); String projectName = split[0]; int buildNumber = Integer.parseInt(split[1]); Job<?,?> job = (Job<?,?>) Jenkins.getInstance().getItemByFullName(projectName); if(job==null) throw new NoSuchElementException("No such job exists: "+projectName); Run<?,?> run = job.getBuildByNumber(buildNumber); if(run==null) throw new NoSuchElementException("No such build: "+string); return run; }
protected int run() throws Exception { Run run = job.getBuildByNumber(number); if (run == null) throw new IllegalArgumentException("No such build #"+number); run.checkPermission(Run.UPDATE); if ("=".equals(description)) { description = IOUtils.toString(stdin); } run.setDescription(description); return 0; }
@Override protected int run() throws Exception { Run<?, ?> run = job.getBuildByNumber(number); if (run == null) { throw new IllegalArgumentException("Build #" + number + " does not exist"); } run.checkPermission(Run.UPDATE); if ("-".equals(displayName)) { displayName = IOUtils.toString(stdin); } run.setDisplayName(displayName); return 0; } }
/** * @since 1.505 */ public @CheckForNull Run<?,?> getUpstreamRun() { Job<?,?> job = Jenkins.getInstance().getItemByFullName(upstreamProject, Job.class); return job != null ? job.getBuildByNumber(upstreamBuild) : null; }
/** * Tries to find a run from an persisted identifier. * @param id as produced by {@link #getExternalizableId} * @return the same run, or null if the job or run was not found * @throws IllegalArgumentException if the ID is malformed */ public @CheckForNull static Run<?,?> fromExternalizableId(String id) throws IllegalArgumentException { int hash = id.lastIndexOf('#'); if (hash <= 0) { throw new IllegalArgumentException("Invalid id"); } String jobName = id.substring(0, hash); int number; try { number = Integer.parseInt(id.substring(hash + 1)); } catch (NumberFormatException x) { throw new IllegalArgumentException(x); } Jenkins j = Jenkins.getInstanceOrNull(); if (j == null) { return null; } Job<?,?> job = j.getItemByFullName(jobName, Job.class); if (job == null) { return null; } return job.getBuildByNumber(number); }
@CLIResolver public RunT getBuildForCLI(@Argument(required=true,metaVar="BUILD#",usage="Build number") String id) throws CmdLineException { try { int n = Integer.parseInt(id); RunT r = getBuildByNumber(n); if (r==null) throw new CmdLineException(null, "No such build '#"+n+"' exists"); return r; } catch (NumberFormatException e) { throw new CmdLineException(null, id+ "is not a number"); } }
/** * If the command is currently running inside a build, return it. Otherwise null. */ protected Run optCurrentlyBuilding() throws CmdLineException { try { CLICommand c = CLICommand.getCurrent(); if (c==null) throw new IllegalStateException("Not executing a CLI command"); String[] envs = c.checkChannel().call(new GetCharacteristicEnvironmentVariables()); if (envs[0]==null || envs[1]==null) return null; Job j = Jenkins.getActiveInstance().getItemByFullName(envs[0],Job.class); if (j==null) throw new IllegalArgumentException("No such job: "+envs[0]); try { Run r = j.getBuildByNumber(Integer.parseInt(envs[1])); if (r==null) throw new IllegalArgumentException("No such build #"+envs[1]+" in "+envs[0]); if (!r.isBuilding()) { throw new IllegalStateException(r + " is not currently being built"); } return r; } catch (NumberFormatException e) { throw new IllegalArgumentException("Invalid build number: "+envs[1]); } } catch (IOException | InterruptedException e) { throw new IllegalArgumentException("Failed to identify the build being executed",e); } }
@Override public Object getDynamic(String token, StaplerRequest req, StaplerResponse rsp) { try { // try to interpret the token as build number return getBuildByNumber(Integer.parseInt(token)); } catch (NumberFormatException e) { // try to map that to widgets for (Widget w : getWidgets()) { if (w.getUrlName().equals(token)) return w; } // is this a permalink? for (Permalink p : getPermalinks()) { if(p.getId().equals(token)) return p.resolve(this); } return super.getDynamic(token, req, rsp); } }
run = job.getBuildByNumber(n); if (run==null) throw new IllegalArgumentException("No such build #"+n);
if(!includeMissing && job.getBuildByNumber(bp.getNumber())==null) continue; // build no longer exists
if (n==RESOLVES_TO_NONE) return null; b = job.getBuildByNumber(n); if (b!=null && apply(b)) return b; // found it (in the most efficient way possible)
/** * Gets the {@link Job} that this pointer points to, * or null if such a job no longer exists. */ public Run getRun() { Job j = getJob(); if(j==null) return null; return j.getBuildByNumber(number); }
/** * Gets the {@link Job} that this pointer points to, * or null if such a job no longer exists. */ public Run getRun() { Job j = getJob(); if(j==null) return null; return j.getBuildByNumber(number); }
protected int run() throws Exception { Run run = job.getBuildByNumber(number); if (run == null) throw new IllegalArgumentException("No such build #"+number); run.checkPermission(Run.UPDATE); if ("=".equals(description)) { description = IOUtils.toString(stdin); } run.setDescription(description); return 0; }
/** * @since 1.505 */ public @CheckForNull Run<?,?> getUpstreamRun() { Job<?,?> job = Jenkins.getInstance().getItemByFullName(upstreamProject, Job.class); return job != null ? job.getBuildByNumber(upstreamBuild) : null; }
@CLIResolver public RunT getBuildForCLI(@Argument(required=true,metaVar="BUILD#",usage="Build number") String id) throws CmdLineException { try { int n = Integer.parseInt(id); RunT r = getBuildByNumber(n); if (r==null) throw new CmdLineException(null, "No such build '#"+n+"' exists"); return r; } catch (NumberFormatException e) { throw new CmdLineException(null, id+ "is not a number"); } }
@CLIResolver public RunT getBuildForCLI(@Argument(required=true,metaVar="BUILD#",usage="Build number") String id) throws CmdLineException { try { int n = Integer.parseInt(id); RunT r = getBuildByNumber(n); if (r==null) throw new CmdLineException(null, "No such build '#"+n+"' exists"); return r; } catch (NumberFormatException e) { throw new CmdLineException(null, id+ "is not a number"); } }