Search in sources :

Example 6 with FilePath

use of hudson.FilePath in project promoted-builds-plugin by jenkinsci.

the class FixedResultBuilder method perform.

@Override
public boolean perform(AbstractBuild<?, ?> build, Launcher launcher, BuildListener listener) throws InterruptedException, IOException {
    FilePath workspace = build.getWorkspace();
    if (workspace == null) {
        throw new AbortException("Workspace is missing in FixedResultBuilder");
    }
    workspace.child("my.file").write("Hello world!", "UTF-8");
    build.setResult(buildResult);
    return true;
}
Also used : FilePath(hudson.FilePath) AbortException(hudson.AbortException)

Example 7 with FilePath

use of hudson.FilePath in project hudson-2.x by hudson.

the class JSONTest method testJSONLeaseFields.

public void testJSONLeaseFields() {
    WorkspaceList.Lease dummyLease = WorkspaceList.Lease.createDummyLease(new FilePath(new File(".")));
    JSONObject json = JSONObject.fromObject(dummyLease);
    assertEquals(json.size(), 1);
}
Also used : FilePath(hudson.FilePath) JSONObject(net.sf.json.JSONObject) WorkspaceList(hudson.slaves.WorkspaceList) File(java.io.File)

Example 8 with FilePath

use of hudson.FilePath in project hudson-2.x by hudson.

the class AbstractProject method poll.

/**
     * Checks if there's any update in SCM, and returns true if any is found.
     *
     * <p>
     * The implementation is responsible for ensuring mutual exclusion between polling and builds
     * if necessary.
     *
     * @since 1.345
     */
public PollingResult poll(TaskListener listener) {
    SCM scm = getScm();
    if (scm == null) {
        listener.getLogger().println(Messages.AbstractProject_NoSCM());
        return NO_CHANGES;
    }
    if (isDisabled()) {
        listener.getLogger().println(Messages.AbstractProject_Disabled());
        return NO_CHANGES;
    }
    R lb = getLastBuild();
    if (lb == null) {
        listener.getLogger().println(Messages.AbstractProject_NoBuilds());
        return isInQueue() ? NO_CHANGES : BUILD_NOW;
    }
    if (pollingBaseline == null) {
        // if we have a persisted baseline, we'll find it by this
        R success = getLastSuccessfulBuild();
        for (R r = lb; r != null; r = r.getPreviousBuild()) {
            SCMRevisionState s = r.getAction(SCMRevisionState.class);
            if (s != null) {
                pollingBaseline = s;
                break;
            }
            // searched far enough
            if (r == success)
                break;
        }
    // NOTE-NO-BASELINE:
    // if we don't have baseline yet, it means the data is built by old Hudson that doesn't set the baseline
    // as action, so we need to compute it. This happens later.
    }
    try {
        if (scm.requiresWorkspaceForPolling()) {
            // lock the workspace of the last build
            FilePath ws = lb.getWorkspace();
            if (ws == null || !ws.exists()) {
                // workspace offline. build now, or nothing will ever be built
                Label label = getAssignedLabel();
                if (label != null && label.isSelfLabel()) {
                    // if the build is fixed on a node, then attempting a build will do us
                    // no good. We should just wait for the slave to come back.
                    listener.getLogger().println(Messages.AbstractProject_NoWorkspace());
                    return NO_CHANGES;
                }
                listener.getLogger().println(ws == null ? Messages.AbstractProject_WorkspaceOffline() : Messages.AbstractProject_NoWorkspace());
                if (isInQueue()) {
                    listener.getLogger().println(Messages.AbstractProject_AwaitingBuildForWorkspace());
                    return NO_CHANGES;
                } else {
                    listener.getLogger().println(Messages.AbstractProject_NewBuildForWorkspace());
                    return BUILD_NOW;
                }
            } else {
                Node node = lb.getBuiltOn();
                if (node == null || node.toComputer() == null) {
                    LOGGER.log(Level.FINE, "Node on which this job previously was built is not available now, build is started on an available node");
                    return isInQueue() ? NO_CHANGES : BUILD_NOW;
                }
                WorkspaceList l = node.toComputer().getWorkspaceList();
                // if doing non-concurrent build, acquire a workspace in a way that causes builds to block for this workspace.
                // this prevents multiple workspaces of the same job --- the behavior of Hudson < 1.319.
                //
                // OTOH, if a concurrent build is chosen, the user is willing to create a multiple workspace,
                // so better throughput is achieved over time (modulo the initial cost of creating that many workspaces)
                // by having multiple workspaces
                WorkspaceList.Lease lease = l.acquire(ws, !concurrentBuild);
                Launcher launcher = ws.createLauncher(listener);
                try {
                    LOGGER.fine("Polling SCM changes of " + getName());
                    if (// see NOTE-NO-BASELINE above
                    pollingBaseline == null)
                        calcPollingBaseline(lb, launcher, listener);
                    PollingResult r = scm.poll(this, launcher, ws, listener, pollingBaseline);
                    pollingBaseline = r.remote;
                    return r;
                } finally {
                    lease.release();
                }
            }
        } else {
            // polling without workspace
            LOGGER.fine("Polling SCM changes of " + getName());
            if (// see NOTE-NO-BASELINE above
            pollingBaseline == null)
                calcPollingBaseline(lb, null, listener);
            PollingResult r = scm.poll(this, null, null, listener, pollingBaseline);
            pollingBaseline = r.remote;
            return r;
        }
    } catch (AbortException e) {
        listener.getLogger().println(e.getMessage());
        listener.fatalError(Messages.AbstractProject_Aborted());
        LOGGER.log(Level.FINE, "Polling " + this + " aborted", e);
        return NO_CHANGES;
    } catch (IOException e) {
        e.printStackTrace(listener.fatalError(e.getMessage()));
        return NO_CHANGES;
    } catch (InterruptedException e) {
        e.printStackTrace(listener.fatalError(Messages.AbstractProject_PollingABorted()));
        return NO_CHANGES;
    }
}
Also used : FilePath(hudson.FilePath) WorkspaceList(hudson.slaves.WorkspaceList) IOException(java.io.IOException) SC_INTERNAL_SERVER_ERROR(javax.servlet.http.HttpServletResponse.SC_INTERNAL_SERVER_ERROR) SCMRevisionState(hudson.scm.SCMRevisionState) PollingResult(hudson.scm.PollingResult) Launcher(hudson.Launcher) SCM(hudson.scm.SCM) NullSCM(hudson.scm.NullSCM) AbortException(hudson.AbortException)

Example 9 with FilePath

use of hudson.FilePath in project hudson-2.x by hudson.

the class AbstractProject method performDelete.

@Override
protected void performDelete() throws IOException, InterruptedException {
    // prevent a new build while a delete operation is in progress
    makeDisabled(true);
    FilePath ws = getWorkspace();
    if (ws != null) {
        Node on = getLastBuiltOn();
        getScm().processWorkspaceBeforeDeletion(this, ws, on);
        if (on != null)
            on.getFileSystemProvisioner().discardWorkspace(this, ws);
    }
    super.performDelete();
}
Also used : FilePath(hudson.FilePath)

Example 10 with FilePath

use of hudson.FilePath in project hudson-2.x by hudson.

the class AbstractProject method doWs.

/**
     * Serves the workspace files.
     */
public DirectoryBrowserSupport doWs(StaplerRequest req, StaplerResponse rsp) throws IOException, ServletException, InterruptedException {
    checkPermission(AbstractProject.WORKSPACE);
    FilePath ws = getSomeWorkspace();
    if ((ws == null) || (!ws.exists())) {
        // if there's no workspace, report a nice error message
        rsp.setStatus(HttpServletResponse.SC_NOT_FOUND);
        req.getView(this, "noWorkspace.jelly").forward(req, rsp);
        return null;
    } else {
        return new DirectoryBrowserSupport(this, ws, getDisplayName() + " workspace", "folder.gif", true);
    }
}
Also used : FilePath(hudson.FilePath)

Aggregations

FilePath (hudson.FilePath)38 IOException (java.io.IOException)17 File (java.io.File)12 URL (java.net.URL)5 EnvVars (hudson.EnvVars)4 AbortException (hudson.AbortException)3 Launcher (hudson.Launcher)3 PrintStream (java.io.PrintStream)3 List (java.util.List)3 BuildListener (hudson.model.BuildListener)2 VirtualChannel (hudson.remoting.VirtualChannel)2 NullSCM (hudson.scm.NullSCM)2 SCM (hudson.scm.SCM)2 WorkspaceList (hudson.slaves.WorkspaceList)2 ArgumentListBuilder (hudson.util.ArgumentListBuilder)2 ArrayList (java.util.ArrayList)2 HashSet (java.util.HashSet)2 ImmutableList (com.google.common.collect.ImmutableList)1 WindowsSlaveInstaller (hudson.lifecycle.WindowsSlaveInstaller)1 MavenModuleSetBuild (hudson.maven.MavenModuleSetBuild)1