Search in sources :

Example 16 with Run

use of hudson.model.Run in project hudson-2.x by hudson.

the class InstallToolCommand method install.

/**
     * Performs an installation.
     */
private int install(ToolInstallation t, BuildIDs id, AbstractProject p) throws IOException, InterruptedException {
    Run b = p.getBuildByNumber(Integer.parseInt(id.number));
    if (b == null)
        throw new AbortException("No such build: " + id.number);
    Executor exec = b.getExecutor();
    if (exec == null)
        throw new AbortException(b.getFullDisplayName() + " is not building");
    Node node = exec.getOwner().getNode();
    if (t instanceof NodeSpecific) {
        NodeSpecific n = (NodeSpecific) t;
        t = (ToolInstallation) n.forNode(node, new StreamTaskListener(stderr));
    }
    if (t instanceof EnvironmentSpecific) {
        EnvironmentSpecific e = (EnvironmentSpecific) t;
        t = (ToolInstallation) e.forEnvironment(EnvVars.getRemote(channel));
    }
    stdout.println(t.getHome());
    return 0;
}
Also used : Executor(hudson.model.Executor) EnvironmentSpecific(hudson.model.EnvironmentSpecific) StreamTaskListener(hudson.util.StreamTaskListener) Node(hudson.model.Node) NodeSpecific(hudson.slaves.NodeSpecific) Run(hudson.model.Run) AbortException(hudson.AbortException)

Example 17 with Run

use of hudson.model.Run in project hudson-2.x by hudson.

the class Functions method decompose.

public static RunUrl decompose(StaplerRequest req) {
    List<Ancestor> ancestors = req.getAncestors();
    // find the first and last Run instances
    Ancestor f = null, l = null;
    for (Ancestor anc : ancestors) {
        if (anc.getObject() instanceof Run) {
            if (f == null)
                f = anc;
            l = anc;
        }
    }
    // there was no Run object
    if (l == null)
        return null;
    String head = f.getPrev().getUrl() + '/';
    String base = l.getUrl();
    String reqUri = req.getOriginalRequestURI();
    // Find "rest" or URI by removing N path components.
    // Not using reqUri.substring(f.getUrl().length()) to avoid mismatches due to
    // url-encoding or extra slashes.  Former may occur in Tomcat (despite the spec saying
    // this string is not decoded, Tomcat apparently decodes this string. You see ' '
    // instead of '%20', which is what the browser has sent), latter may occur in some
    // proxy or URL-rewriting setups where extra slashes are inadvertently added.
    String furl = f.getUrl();
    int slashCount = 0;
    // Count components in ancestor URL
    for (int i = furl.indexOf('/'); i >= 0; i = furl.indexOf('/', i + 1)) slashCount++;
    // Remove that many from request URL, ignoring extra slashes
    String rest = reqUri.replaceFirst("(?:/+[^/]*){" + slashCount + "}", "");
    return new RunUrl((Run) f.getObject(), head, base, rest);
}
Also used : Run(hudson.model.Run) Ancestor(org.kohsuke.stapler.Ancestor)

Example 18 with Run

use of hudson.model.Run in project hudson-2.x by hudson.

the class LogRotator method deleteBuilds.

/**
     * Performs builds deletion
     *
     * @param builds list of builds
     * @param lastSuccessBuild last success build
     * @param lastStableBuild last stable build
     * @param cal calendar if configured
     * @throws IOException if configured
     */
private void deleteBuilds(List<? extends Run<?, ?>> builds, Run lastSuccessBuild, Run lastStableBuild, Calendar cal) throws IOException {
    for (Run currentBuild : builds) {
        if (allowDeleteBuild(lastSuccessBuild, lastStableBuild, currentBuild, cal)) {
            LOGGER.log(FINER, currentBuild.getFullDisplayName() + " is to be removed");
            currentBuild.delete();
        }
    }
}
Also used : Run(hudson.model.Run)

Example 19 with Run

use of hudson.model.Run in project blueocean-plugin by jenkinsci.

the class PipelineNodeUtil method getCauseOfBlockage.

/**
     *  Gives cause of block for declarative style plugin where agent (node block) is declared inside a stage.
     *  <pre>
     *    pipeline {
     *      agent none
     *      stages {
     *          stage ('first') {
     *              agent {
     *                  label 'first'
     *              }
     *              steps{
     *                  sh 'echo "from first"'
     *              }
     *          }
     *      }
     *    }
     *  </pre>
     *
     * @param stage stage's {@link FlowNode}
     * @param nodeBlock agent or node block's {@link FlowNode}
     * @param run {@link WorkflowRun} instance
     * @return cause of block if present, nul otherwise
     * @throws IOException in case of IOException
     * @throws InterruptedException in case of Interrupted exception
     */
@CheckForNull
public static String getCauseOfBlockage(@Nonnull FlowNode stage, @Nullable FlowNode nodeBlock, @Nonnull WorkflowRun run) throws IOException, InterruptedException {
    if (nodeBlock != null) {
        //Check and see if this node block is inside this stage
        for (FlowNode p : nodeBlock.getParents()) {
            if (p.equals(stage)) {
                //see if there is blocked item in queue
                for (Queue.Item i : Jenkins.getInstance().getQueue().getItems()) {
                    if (i.task instanceof ExecutorStepExecution.PlaceholderTask) {
                        ExecutorStepExecution.PlaceholderTask task = (ExecutorStepExecution.PlaceholderTask) i.task;
                        String cause = i.getCauseOfBlockage().getShortDescription();
                        if (task.getCauseOfBlockage() != null) {
                            cause = task.getCauseOfBlockage().getShortDescription();
                        }
                        Run r = task.runForDisplay();
                        //Set cause if its there and run and node block in the queue is same as the one we
                        if (cause != null && r != null && r.equals(run) && task.getNode() != null && task.getNode().equals(nodeBlock)) {
                            return cause;
                        }
                    }
                }
            }
        }
    }
    return null;
}
Also used : ExecutorStepExecution(org.jenkinsci.plugins.workflow.support.steps.ExecutorStepExecution) BlueRun(io.jenkins.blueocean.rest.model.BlueRun) Run(hudson.model.Run) WorkflowRun(org.jenkinsci.plugins.workflow.job.WorkflowRun) Queue(hudson.model.Queue) FlowNode(org.jenkinsci.plugins.workflow.graph.FlowNode) CheckForNull(javax.annotation.CheckForNull)

Example 20 with Run

use of hudson.model.Run in project blueocean-plugin by jenkinsci.

the class PipelineApiTest method getPipelineJobRunsTest.

@Test
public void getPipelineJobRunsTest() throws Exception {
    WorkflowJob job1 = j.jenkins.createProject(WorkflowJob.class, "pipeline1");
    job1.setDefinition(new CpsFlowDefinition("" + "node {" + "   stage ('Build1'); " + "   echo ('Building'); " + "   stage ('Test1'); " + "   echo ('Testing'); " + "}"));
    WorkflowRun b1 = job1.scheduleBuild2(0).get();
    j.assertBuildStatusSuccess(b1);
    WorkflowRun b2 = job1.scheduleBuild2(0).get();
    j.assertBuildStatusSuccess(b2);
    Run[] runs = { b2, b1 };
    List<Map> runResponses = get("/organizations/jenkins/pipelines/pipeline1/runs", List.class);
    for (int i = 0; i < runs.length; i++) {
        validateRun(runs[i], runResponses.get(i));
    }
    ;
}
Also used : CpsFlowDefinition(org.jenkinsci.plugins.workflow.cps.CpsFlowDefinition) Run(hudson.model.Run) WorkflowRun(org.jenkinsci.plugins.workflow.job.WorkflowRun) WorkflowJob(org.jenkinsci.plugins.workflow.job.WorkflowJob) Map(java.util.Map) WorkflowRun(org.jenkinsci.plugins.workflow.job.WorkflowRun) Test(org.junit.Test)

Aggregations

Run (hudson.model.Run)26 FreeStyleProject (hudson.model.FreeStyleProject)5 Job (hudson.model.Job)5 Test (org.junit.Test)5 Item (hudson.model.Item)4 Shell (hudson.tasks.Shell)4 BlueRun (io.jenkins.blueocean.rest.model.BlueRun)4 Map (java.util.Map)4 WorkflowRun (org.jenkinsci.plugins.workflow.job.WorkflowRun)4 ArtifactArchiver (hudson.tasks.ArtifactArchiver)3 ArrayList (java.util.ArrayList)3 AbstractProject (hudson.model.AbstractProject)2 ViolationsReport (hudson.plugins.violations.ViolationsReport)2 DataSetBuilder (hudson.util.DataSetBuilder)2 IOException (java.io.IOException)2 Nonnull (javax.annotation.Nonnull)2 MultiBranchProject (jenkins.branch.MultiBranchProject)2 Jenkins (jenkins.model.Jenkins)2 WorkflowJob (org.jenkinsci.plugins.workflow.job.WorkflowJob)2 Ancestor (org.kohsuke.stapler.Ancestor)2