Refine search
/** * Convenience method for getting the action for a specific run. * * @param run the run to get the action for. * @return the FailureCauseBuildAction. */ public FailureCauseBuildAction getActionForBuild(MatrixRun run) { return run.getAction(FailureCauseBuildAction.class); }
@Override public void buildEnvironmentFor(@Nonnull Run r, @Nonnull EnvVars envs, @Nonnull TaskListener listener) throws IOException, InterruptedException { GitLabWebHookCause cause = null; if (r instanceof MatrixRun) { MatrixBuild parent = ((MatrixRun)r).getParentBuild(); if (parent != null) { cause = (GitLabWebHookCause) parent.getCause(GitLabWebHookCause.class); } } else { cause = (GitLabWebHookCause) r.getCause(GitLabWebHookCause.class); } if (cause != null) { envs.overrideAll(cause.getData().getBuildVariables()); } } }
public boolean apply(@Nullable MatrixRun run) { if (run == null) { return false; } if (StringUtils.isBlank(getCombinationFilter())) { // no combination filter stands for all children. return true; } Combination c = run.getParent().getCombination(); AxisList axes = run.getParent().getParent().getAxes(); return c.evalGroovyExpression(axes, getCombinationFilter()); } }
@Override public void perform(Job _job) throws IOException, InterruptedException { // Let superclass handle clearing artifacts, if configured: super.perform(_job); MatrixConfiguration job = (MatrixConfiguration) _job; // copy it to the array because we'll be deleting builds as we go. for( MatrixRun r : job.getBuilds().toArray(new MatrixRun[0]) ) { if(job.getParent().getBuildByNumber(r.getNumber())==null) r.delete(); } if(!job.isActiveConfiguration() && job.getLastBuild()==null) job.delete(); } }
/** * Gets the {@link MatrixBuild} that has the same build number. * * @return * null if no such build exists, which happens when the module build * is manually triggered. */ public MatrixBuild getParentBuild() { return getParent().getParent().getBuildByNumber(getNumber()); }
public List<ClaimColumnInformation> getAction(Job<?,?> job) { List<ClaimColumnInformation> result = new ArrayList<ClaimColumnInformation>(); Run<?,?> run = job.getLastCompletedBuild(); if (run != null) { if (run instanceof hudson.matrix.MatrixBuild) { MatrixBuild matrixBuild = (hudson.matrix.MatrixBuild) run; for (MatrixRun combination : matrixBuild.getRuns()) { ClaimBuildAction action = combination.getAction(ClaimBuildAction.class); if (combination.getResult().isWorseThan(Result.SUCCESS) && action != null && action.isClaimed()) { ClaimColumnInformation holder = new ClaimColumnInformation(); holder.setClaim(action); holder.setMatrix(true); holder.setCombinationName(combination.getParent().getCombination().toString()+": "); result.add(holder); } } } else { ClaimBuildAction action = run.getAction(ClaimBuildAction.class); if (action != null && action.isClaimed()) { ClaimColumnInformation holder = new ClaimColumnInformation(); holder.setClaim(action); result.add(holder); } } } return result; }
/** * Asserts that the outcome of the build is a specific outcome. */ public <R extends Run> R assertBuildStatus(Result status, R r) throws Exception { if(status==r.getResult()) return r; // dump the build output in failure message String msg = "unexpected build status; build log was:\n------\n" + getLog(r) + "\n------\n"; if(r instanceof MatrixBuild) { MatrixBuild mb = (MatrixBuild)r; for (MatrixRun mr : mb.getRuns()) { msg+="--- "+mr.getParent().getCombination()+" ---\n"+getLog(mr)+"\n------\n"; } } assertEquals(msg, status,r.getResult()); return r; }
@Override protected Lease decideWorkspace(Node n, WorkspaceList wsl) throws InterruptedException, IOException { // Map current combination to a directory subtree, e.g. 'axis1=a,axis2=b' to 'axis1/a/axis2/b'. String subtree; if(useShortWorkspaceName) { subtree = getParent().getDigestName(); } else { subtree = getParent().getCombination().toString('/','/', true); } String customWorkspace = getParent().getParent().getCustomWorkspace(); if (customWorkspace != null) { // Use custom workspace as defined in the matrix project settings. FilePath ws = n.getRootPath().child(getEnvironment(listener).expand(customWorkspace)); // We allow custom workspaces to be used concurrently between jobs. return Lease.createDummyLease(ws.child(subtree)); } else { // Use default workspace as assigned by Hudson. Node node = getBuiltOn(); FilePath ws = node.getWorkspaceFor(getParent().getParent()); // Allocate unique workspace (not to be shared between jobs and runs). return wsl.allocate(ws.child(subtree)); } } }
@Override protected Lease decideWorkspace(Node n, WorkspaceList wsl) throws InterruptedException, IOException { MatrixProject mp = getParent().getParent(); // lock is done at the parent level, so that concurrent MatrixProjects get respective workspace, // but within MatrixConfigurations that belong to the same MatrixBuild. // if MatrixProject is configured with custom workspace, we assume that the user knows what he's doing // and try not to append unique random suffix. Lease baseLease = getParentWorkspaceLease(n,wsl); // resolve the relative path against the parent workspace, which needs locking FilePath baseDir = baseLease.path; // prepare variables that can be used in the child workspace setting EnvVars env = getEnvironment(listener); env.put("COMBINATION",getParent().getCombination().toString('/','/')); // e.g., "axis1/a/axis2/b" env.put("SHORT_COMBINATION",getParent().getDigestName()); // e.g., "0fbcab35" env.put("PARENT_WORKSPACE",baseDir.getRemote()); env.putAll(getBuildVariables()); // child workspace need no individual locks, whether or not we use custom workspace String childWs = mp.getChildCustomWorkspace(); return Lease.createLinkedDummyLease(baseDir.child(env.expand(childWs)),baseLease); } }
/** * Method for remove matrix run actions. * * @param build the MatrixBuild. */ public void removeRunActions(MatrixBuild build) { List<MatrixRun> runs = build.getRuns(); for (MatrixRun run : runs) { if (run.getNumber() == build.getNumber()) { FailureCauseBuildAction fcba = run.getAction(FailureCauseBuildAction.class); if (fcba != null) { run.getActions().remove(fcba); } FailureCauseMatrixBuildAction fcmba = run.getAction(FailureCauseMatrixBuildAction.class); if (fcmba != null) { run.getActions().remove(fcmba); } } } }
MatrixRun b = c.getBuildByNumber(getNumber()); if (b != null && !b.isBuilding()) { buildResult = b.getResult(); Queue.Item qi = c.getQueueItem(); if (b == null && qi == null) { appearsCancelledCount++; listener.getLogger().println(Messages.MatrixBuild_AppearsCancelled(c.getDisplayName())); buildResult = Result.ABORTED;
@Override protected MatrixRun newBuild() throws IOException { // for every MatrixRun there should be a parent MatrixBuild MatrixBuild lb = getParent().getLastBuild(); MatrixRun lastBuild = new MatrixRun(this, lb.getTimestamp()); lastBuild.number = lb.getNumber(); builds.put(lastBuild); return lastBuild; }
protected Lease getParentWorkspaceLease(Node n, WorkspaceList wsl) throws InterruptedException, IOException { MatrixProject mp = getParent().getParent(); String customWorkspace = mp.getCustomWorkspace(); if (customWorkspace != null) { final FilePath nodeRoot = n.getRootPath(); if (nodeRoot == null) { throw new IOException("Cannot retrieve the node's root. Most probably it's offline"); } // we allow custom workspaces to be concurrently used between jobs. return Lease.createDummyLease(nodeRoot.child(getEnvironment(listener).expand(customWorkspace))); } final FilePath workspace = n.getWorkspaceFor(mp); if (workspace == null) { throw new IOException("Cannot retrieve the node's workspace for " + mp + ". Most probably the node is offline"); } return wsl.allocate(workspace, getParentBuild()); }
@Override public void onLoad(Run<?, ?> r) { if (r instanceof MatrixRun) { MatrixRun run = (MatrixRun) r; ParametersAction action = run.getParentBuild().getAction(ParametersAction.class); if (action != null) { // Parameters of build and its runs are guaranteed to be the same. Even the actual instances are the same // until it gets (re)loaded from disk when the parameters reside in memory 1+N times squandering memory. // This populates now volatile collection with parameters shared between the build and all its runs bringing // the space complexity back to 1. parameters = action.getParameters(); } else { parameters = Collections.emptyList(); } } }
/** * True if this build didn't do a full build and it is depending on the result of the previous build. */ public boolean isPartial() { for(MatrixConfiguration c : getParent().getActiveConfigurations()) { MatrixRun b = c.getNearestOldBuild(getNumber()); if (b != null && b.getNumber()!=getNumber()) return true; } return false; }
LOGGER.log(Level.WARNING, "JENKINS-26582: ignoring apparent attempt to trigger {0} without its parent", getFullName()); return null; lb = getParent().getLastBuild(); if (lb == null) { LOGGER.log(Level.WARNING, "cannot start a build of {0} since its parent has no builds at all", getFullName()); return null; LOGGER.log(Level.WARNING, "guessing that the correct build of {0} is #{1}", new Object[] {getFullName(), lb.getNumber()}); MatrixRun lastBuild = new MatrixRun(this, lb.getTimestamp()); lastBuild.number = lb.getNumber(); _getRuns().put(lastBuild);
/** * If the parent {@link MatrixBuild} is kept, keep this record too. */ @Override public String getWhyKeepLog() { MatrixBuild pb = getParentBuild(); if(pb!=null && pb.getWhyKeepLog()!=null) return Messages.MatrixRun_KeptBecauseOfParent(pb); return super.getWhyKeepLog(); }
/** * 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() { MatrixBuild lcb = getParent().getLastCompletedBuild(); if (lcb == null) { return 0; } int n = lcb.getNumber() + 1; MatrixRun lb = getLastBuild(); if (lb != null) { n = Math.max(n, lb.getNumber() + 1); } return n; }
private boolean isEligibleJobType(@Nonnull Run<?, ?> build) { final Job job; if (build instanceof MatrixRun) { job = ((MatrixRun) build).getParentBuild().getParent(); } else { job = build.getParent(); } return job instanceof BuildableItemWithBuildWrappers; }
@Override public void checkPermission(hudson.security.Permission p) { MatrixBuild parentBuild = getParentBuild(); if(parentBuild != null) { parentBuild.checkPermission(p); } };