Search in sources :

Example 36 with FilePath

use of hudson.FilePath in project blueocean-plugin by jenkinsci.

the class PipelineNodeTest method testTestsInStage.

@Test
public void testTestsInStage() throws Exception {
    String pipeline = "" + "node {\n" + "  stage ('dev') {\n" + "    junit('*.xml')\n" + "  }\n" + "  stage ('prod') {\n" + "    junit('*.xml')\n" + "  }\n" + "  stage ('testing') {\n" + "    parallel(first: {\n" + "        junit('*.xml')\n" + "      },\n" + "      second: {\n" + "        junit('*.xml')\n" + "      })\n" + "  }\n" + "}\n";
    WorkflowJob job1 = j.jenkins.createProject(WorkflowJob.class, "pipeline1");
    job1.setDefinition(new CpsFlowDefinition(pipeline, true));
    FilePath ws = j.jenkins.getWorkspaceFor(job1);
    FilePath testFile = ws.child("test-result.xml");
    testFile.copyFrom(PipelineNodeTest.class.getResource("testResult.xml"));
    WorkflowRun b1 = job1.scheduleBuild2(0).get();
    j.assertBuildStatusSuccess(b1);
    NodeGraphBuilder builder = NodeGraphBuilder.NodeGraphBuilderFactory.getInstance(b1);
    List<FlowNode> stages = getStages(builder);
    Assert.assertEquals(3, stages.size());
    List<Map> resp = get("/organizations/jenkins/pipelines/pipeline1/runs/1/nodes/", List.class);
    Assert.assertEquals(5, resp.size());
    resp = get("/organizations/jenkins/pipelines/pipeline1/runs/1/tests/", List.class);
    Assert.assertEquals(4, resp.size());
    Assert.assertEquals("dev / testDummyMethod – DummyTest", resp.get(0).get("name"));
    Assert.assertEquals("prod / testDummyMethod – DummyTest", resp.get(1).get("name"));
    Assert.assertEquals("testing / first / testDummyMethod – DummyTest", resp.get(2).get("name"));
    Assert.assertEquals("testing / second / testDummyMethod – DummyTest", resp.get(3).get("name"));
}
Also used : FilePath(hudson.FilePath) CpsFlowDefinition(org.jenkinsci.plugins.workflow.cps.CpsFlowDefinition) RunList(hudson.util.RunList) ImmutableList(com.google.common.collect.ImmutableList) List(java.util.List) WorkflowJob(org.jenkinsci.plugins.workflow.job.WorkflowJob) Map(java.util.Map) ImmutableMap(com.google.common.collect.ImmutableMap) WorkflowRun(org.jenkinsci.plugins.workflow.job.WorkflowRun) FlowNode(org.jenkinsci.plugins.workflow.graph.FlowNode) Test(org.junit.Test)

Example 37 with FilePath

use of hudson.FilePath in project violations-plugin by jenkinsci.

the class ViolationsPublisher method perform.

/**
 * Called by hudson at the end of a build.
 *
 * @param build
 *            the build
 * @param launcher
 *            the launcher
 * @param listener
 *            for reporting errors
 * @return true always.
 * @throws InterruptedException
 *             if user cancels the operation
 * @throws IOException
 *             if problem parsing the xml files
 */
@Override
public boolean perform(AbstractBuild<?, ?> build, Launcher launcher, BuildListener listener) throws InterruptedException, IOException {
    FilePath htmlPath = new FilePath(new File(build.getProject().getRootDir(), VIOLATIONS));
    FilePath targetPath = new FilePath(new File(build.getRootDir(), VIOLATIONS));
    FilePath workspace = build.getWorkspace();
    build.getActions().add(createBuildAction(workspace, targetPath, htmlPath, config, build, listener));
    return true;
}
Also used : FilePath(hudson.FilePath) File(java.io.File)

Example 38 with FilePath

use of hudson.FilePath in project violations-plugin by jenkinsci.

the class ExecuteFilePath method execute.

/**
 * Parse the file.
 * @throws IOException if there is a problem.
 * @throws InterruptedException if interrupted.
 */
public void execute() throws IOException, InterruptedException {
    boolean seenException = false;
    FilePath f = targetDir.child(filename);
    PrintWriter w = new PrintWriter(new BufferedWriter(new OutputStreamWriter(f.write(), // ? for html //
    "UTF-8")));
    try {
        ex.execute(w);
    } catch (IOException ex) {
        seenException = true;
        throw ex;
    } finally {
        CloseUtil.close(w, seenException);
    }
}
Also used : FilePath(hudson.FilePath) OutputStreamWriter(java.io.OutputStreamWriter) IOException(java.io.IOException) PrintWriter(java.io.PrintWriter) BufferedWriter(java.io.BufferedWriter)

Example 39 with FilePath

use of hudson.FilePath in project violations-plugin by jenkinsci.

the class StyleCopParser method parseViolations.

/**
 * Parse the Violation tag and add it to the build model
 * @param elements list of Violation tags
 */
private void parseViolations(List<Element> elements) throws IOException {
    for (Element element : elements) {
        Violation violation = new Violation();
        violation.setLine(getString(element, "LineNumber"));
        violation.setMessage(element.getTextContent() + " (" + getString(element, "RuleId") + ")");
        violation.setSeverity(Severity.MEDIUM);
        violation.setSeverityLevel(Severity.MEDIUM_VALUE);
        violation.setType(TYPE_NAME);
        String temp = getString(element, "RuleNamespace");
        int i = temp.lastIndexOf('.');
        if (i != -1) {
            violation.setSource(temp.substring(i));
        } else {
            violation.setSource(getString(element, "RuleId"));
        }
        // Add the violation to the model
        String displayName = new FilePath(reportParentFile).child(getString(element, "Source")).getRemote();
        displayName = ParseUtil.resolveAbsoluteName(reportParentFile, displayName);
        /* TODO: apply heuristics to fine the source.

                StyleCop just puts whatever path representation it gets from MSBuild into @Source,
                which can be relative (to the current directory MSBuild run in, which we won't know.)
                In such a case, there's really no reliable way for us to deterministically figure out
                where the source code is in the source tree.

                The resolution against 'reportParentFile' is quite arbitrary in that sense and only
                works if the report is created into the same directory as the MSBuild current directory,
                but it is a backward compatible behaviour.
             */
        FullFileModel fileModel = model.getFileModel(displayName);
        fileModel.addViolation(violation);
    }
}
Also used : Violation(hudson.plugins.violations.model.Violation) FilePath(hudson.FilePath) FullFileModel(hudson.plugins.violations.model.FullFileModel) Element(org.w3c.dom.Element)

Aggregations

FilePath (hudson.FilePath)39 IOException (java.io.IOException)17 File (java.io.File)12 URL (java.net.URL)5 EnvVars (hudson.EnvVars)4 List (java.util.List)4 AbortException (hudson.AbortException)3 Launcher (hudson.Launcher)3 PrintStream (java.io.PrintStream)3 ImmutableList (com.google.common.collect.ImmutableList)2 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 ImmutableMap (com.google.common.collect.ImmutableMap)1 WindowsSlaveInstaller (hudson.lifecycle.WindowsSlaveInstaller)1