Refine search
/** * Picks up a {@link RepositoryBrowser} that matches the * given {@link SCM} from existing other jobs. * * @return * null if no applicable configuration was found. */ private RepositoryBrowser infer() { for( AbstractProject p : Jenkins.getInstance().allItems(AbstractProject.class) ) { SCM scm = p.getScm(); if (scm!=null && scm.getClass()==owner.getClass() && scm.getBrowser()!=null && ((SCMDescriptor)scm.getDescriptor()).isBrowserReusable(scm,owner)) { return scm.getBrowser(); } } return null; } }
/** * Adds environmental variables for the builds to the given map. * * <p> * This can be used to propagate information from SCM to builds * (for example, SVN revision number.) * * <p> * This method is invoked whenever someone does {@link AbstractBuild#getEnvironment(TaskListener)}, via * {@link #buildEnvVars(AbstractBuild, Map)}, which can be before/after your checkout method is invoked. So if you * are going to provide information about check out (like SVN revision number that was checked out), be prepared * for the possibility that the check out hasn't happened yet. * * @since 2.60 */ public void buildEnvironment(@Nonnull Run<?,?> build, @Nonnull Map<String,String> env) { if (build instanceof AbstractBuild) { buildEnvVars((AbstractBuild)build, env); } }
if (scm.requiresWorkspaceForPolling()) { R b = getSomeBuildWithExistingWorkspace(); if (b == null) b = getLastBuild(); FilePath ws=b.getWorkspace(); WorkspaceOfflineReason workspaceOfflineReason = workspaceOffline( b ); if ( workspaceOfflineReason != null ) { return BUILD_NOW; } else { WorkspaceList l = b.getBuiltOn().toComputer().getWorkspaceList(); return pollWithWorkspace(listener, scm, b, ws, l); if (pollingBaseline==null) // see NOTE-NO-BASELINE above calcPollingBaseline(getLastBuild(),null,listener); PollingResult r = scm.poll(this, null, null, listener, pollingBaseline); pollingBaseline = r.remote; return r;
/** * Convenience method for the caller to handle the backward compatibility between pre 1.345 SCMs. */ public final PollingResult poll(AbstractProject<?,?> project, Launcher launcher, FilePath workspace, TaskListener listener, SCMRevisionState baseline) throws IOException, InterruptedException { if (is1_346OrLater()) { // This is to work around HUDSON-5827 in a general way. // don't let the SCM.compareRemoteRevisionWith(...) see SCMRevisionState that it didn't produce. SCMRevisionState baseline2; if (baseline!=SCMRevisionState.NONE) { baseline2 = baseline; } else { baseline2 = calcRevisionsFromBuild(project.getLastBuild(), launcher, listener); } return compareRemoteRevisionWith(project, launcher, workspace, listener, baseline2); } else { return pollChanges(project,launcher,workspace,listener) ? PollingResult.SIGNIFICANT : PollingResult.NO_CHANGES; } }
/** * @deprecated as of 1.382. * Use/derive from {@link #getModuleRoots(FilePath, AbstractBuild)} instead. */ @Deprecated public FilePath[] getModuleRoots(FilePath workspace) { if (Util.isOverridden(SCM.class,getClass(),"getModuleRoots", FilePath.class, AbstractBuild.class)) // if the subtype already derives newer getModuleRoots(FilePath,AbstractBuild), delegate to it return getModuleRoots(workspace,null); // otherwise the default implementation return new FilePath[] { getModuleRoot(workspace), }; }
public RepositoryBrowser get() { if (cacheGeneration == -1) { return cache; } SCMDescriptor<?> d = owner.getDescriptor(); RepositoryBrowser<?> dflt = owner.guessBrowser(); if (dflt != null) { cache = dflt; cacheGeneration = -1; return cache; } int g = d.generation; if(g!=cacheGeneration) { cacheGeneration = g; cache = infer(); } return cache; }
@Override public boolean perform(@Nonnull AbstractBuild<?, ?> build, @Nonnull Launcher launcher, @Nonnull BuildListener listener) throws InterruptedException, IOException { FilePath ws = build.getWorkspace(); EnvInjectActionSetter envInjectActionSetter = new EnvInjectActionSetter(ws); EnvInjectEnvVars envInjectEnvVarsService = new EnvInjectEnvVars(logger); variables.put("WORKSPACE", ws.getRemote()); SCM scm = build.getProject().getScm(); if (scm != null) { scm.buildEnvVars(build, variables); build.addAction(new EnvInjectBuilderContributionAction(resultVariables));
@Deprecated public boolean checkout(AbstractBuild<?,?> build, Launcher launcher, FilePath workspace, BuildListener listener, @Nonnull File changelogFile) throws IOException, InterruptedException { AbstractBuild<?,?> prev = build.getPreviousBuild(); checkout((Run) build, launcher, workspace, listener, changelogFile, prev != null ? prev.getAction(SCMRevisionState.class) : null); return true; }
public void checkout(@Nonnull Run<?,?> build, @Nonnull Launcher launcher, @Nonnull FilePath workspace, @Nonnull TaskListener listener, @CheckForNull File changelogFile, @CheckForNull SCMRevisionState baseline) throws IOException, InterruptedException { if (build instanceof AbstractBuild && listener instanceof BuildListener && Util.isOverridden(SCM.class, getClass(), "checkout", AbstractBuild.class, Launcher.class, FilePath.class, BuildListener.class, File.class)) { if (changelogFile == null) { changelogFile = File.createTempFile("changelog", ".xml"); try { if (!checkout((AbstractBuild) build, launcher, workspace, (BuildListener) listener, changelogFile)) { throw new AbortException(); Util.deleteFile(changelogFile); if (!checkout((AbstractBuild) build, launcher, workspace, (BuildListener) listener, changelogFile)) { throw new AbortException();
public @CheckForNull SCMRevisionState calcRevisionsFromBuild(@Nonnull Run<?,?> build, @Nullable FilePath workspace, @Nullable Launcher launcher, @Nonnull TaskListener listener) throws IOException, InterruptedException { if (build instanceof AbstractBuild && Util.isOverridden(SCM.class, getClass(), "calcRevisionsFromBuild", AbstractBuild.class, Launcher.class, TaskListener.class)) { return calcRevisionsFromBuild((AbstractBuild) build, launcher, listener); } else { throw new AbstractMethodError("you must override the new calcRevisionsFromBuild overload");
if (isDisabled()) { listener.getLogger().println(Messages.AbstractProject_Disabled()); return NO_CHANGES; R lb = getLastBuild(); if (lb == null) { listener.getLogger().println(Messages.AbstractProject_NoBuilds()); if (scm.requiresWorkspaceForPolling()) { FilePath ws = lb.getWorkspace(); if (ws == null || !ws.exists()) { Label label = getAssignedLabel(); calcPollingBaseline(lb, launcher, listener); PollingResult r = scm.poll(this, launcher, ws, listener, pollingBaseline); pollingBaseline = r.remote; return r; calcPollingBaseline(lb, null, listener); PollingResult r = scm.poll(this, null, null, listener, pollingBaseline); pollingBaseline = r.remote; return r;
@Override public EnvVars getEnvironment(TaskListener log) throws IOException, InterruptedException { EnvVars env = super.getEnvironment(log); FilePath ws = getWorkspace(); if (ws!=null) // if this is done very early on in the build, workspace may not be decided yet. see HUDSON-3997 env.put("WORKSPACE", ws.getRemote()); // 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",""); JDK jdk = project.getJDK(); if (jdk != null) { Computer computer = Computer.currentComputer(); if (computer != null) { // just in case were not in a build jdk = jdk.forNode(computer.getNode(), log); } jdk.buildEnvVars(env); } project.getScm().buildEnvVars(this,env); if (buildEnvironments!=null) for (Environment e : buildEnvironments) e.buildEnvVars(env); for (EnvironmentContributingAction a : Util.filter(getActions(),EnvironmentContributingAction.class)) a.buildEnvVars(this,env); EnvVars.resolve(env); return env; }
public boolean checkout(AbstractBuild build, Launcher launcher, BuildListener listener, File changelogFile) throws IOException, InterruptedException { SCM scm = getScm(); if(scm==null) return true; // no SCM FilePath workspace = build.getWorkspace(); if(workspace!=null){ workspace.mkdirs(); } else { throw new AbortException("Cannot checkout SCM, workspace is not defined"); } boolean r = scm.checkout(build, launcher, workspace, listener, changelogFile); if (r) { // Only calcRevisionsFromBuild if checkout was successful. Note that modern SCM implementations // won't reach this line anyway, as they throw AbortExceptions on checkout failure. calcPollingBaseline(build, launcher, listener); } return r; }
@Override public EnvVars getEnvironment(TaskListener log) throws IOException, InterruptedException { EnvVars env = super.getEnvironment(log); FilePath ws = getWorkspace(); if (ws!=null) // if this is done very early on in the build, workspace may not be decided yet. see HUDSON-3997 env.put("WORKSPACE", ws.getRemote()); project.getScm().buildEnvVars(this,env); if (buildEnvironments!=null) for (Environment e : buildEnvironments) e.buildEnvVars(env); for (EnvironmentContributingAction a : getActions(EnvironmentContributingAction.class)) a.buildEnvVars(this,env); EnvVars.resolve(env); return env; }
/** * Returns the root directories of all checked-out modules. * <p> * Some SCMs support checking out multiple modules into the same workspace. * In these cases, the returned array will have a length greater than one. * @return The roots of all modules checked out from the SCM. */ public FilePath[] getModuleRoots() { FilePath ws = getWorkspace(); if (ws==null) return null; return getParent().getScm().getModuleRoots(ws, this); }
/** * Returns the root directory of the checked-out module. * <p> * This is usually where {@code pom.xml}, {@code build.xml} * and so on exists. */ public final FilePath getModuleRoot() { FilePath ws = getWorkspace(); if (ws==null) return null; return getParent().getScm().getModuleRoot(ws, this); }
private void assertRevision(@CheckForNull SCMRevision rev, @CheckForNull String expectedFile, @NonNull SCMSource source, @NonNull Run<?,?> run, @NonNull TaskListener listener) throws Exception { if (rev == null) { assertNull(expectedFile); return; } FilePath ws = new FilePath(run.getRootDir()).child("tmp"); try { source.build(rev.getHead(), rev).checkout(run, new Launcher.LocalLauncher(listener), ws, listener, null, SCMRevisionState.NONE); } catch (Exception x) { x.printStackTrace(listener.error("could not check out")); assertNull(expectedFile); return; } FilePath file = ws.child("file"); assertEquals(expectedFile, file.exists() ? file.readToString() : null); }
TaskListener listener, List<Action> actions) { PrintStream logger = listener.getLogger(); if(trigger.getStrategy().evaluate(trigger.getThreshold(), build.getResult())) { AbstractProject p = getDownstreamProject(); ChangeLogSet changes = build.getChangeSet(); if (changes.isEmptySet()) logger.println(Messages.DownstreamTrigger_NoSCMChanges(build.getProject().getName())); return false; if (p.getScm().requiresWorkspaceForPolling()) { logger.println(Messages.DownstreamTrigger_StartedAsynchPoll(p.getName())); Runnable run = getPoller(p, new Cause.UpstreamCause((Run<?,?>)build), actions); DownstreamTrigger.executeForProject(p, run);
@Deprecated public ChangeLogSet<? extends Entry> parse(AbstractBuild build, File changelogFile) throws IOException, SAXException { return parse((Run) build, build.getProject().getScm().getEffectiveBrowser(), changelogFile); } }
/** * Pushes the baseline up to the newly checked out revision. */ private void calcPollingBaseline(AbstractBuild build, Launcher launcher, TaskListener listener) throws IOException, InterruptedException { SCMRevisionState baseline = build.getAction(SCMRevisionState.class); if (baseline==null) { try { baseline = getScm().calcRevisionsFromBuild(build, launcher, listener); } catch (AbstractMethodError e) { baseline = SCMRevisionState.NONE; // pre-1.345 SCM implementations, which doesn't use the baseline in polling } if (baseline!=null) build.addAction(baseline); } pollingBaseline = baseline; }