Search in sources :

Example 76 with WorkflowRun

use of org.jenkinsci.plugins.workflow.job.WorkflowRun in project blueocean-plugin by jenkinsci.

the class JobAnalyticsTest method testJobAnalytics.

@Test
public void testJobAnalytics() throws Exception {
    // Freestyle jobs
    j.createFreeStyleProject("freestyle1").save();
    j.createFreeStyleProject("freestyle2").save();
    // Matrix job
    j.createProject(MatrixProject.class, "bob");
    // Create single scripted pipeline
    WorkflowJob scriptedSingle = createWorkflowJobWithJenkinsfile(getClass(), "JobAnalyticsTest-scripted.jenkinsfile");
    WorkflowRun scriptedSingleRun = scriptedSingle.scheduleBuild2(0, new CauseAction()).waitForStart();
    j.waitForCompletion(scriptedSingleRun);
    // Create single declarative pipeline
    WorkflowJob declarativeSingle = createWorkflowJobWithJenkinsfile(getClass(), "JobAnalyticsTest-declarative.jenkinsfile");
    WorkflowRun declarativeSingleRun = declarativeSingle.scheduleBuild2(0, new CauseAction()).waitForStart();
    j.waitForCompletion(declarativeSingleRun);
    // Create Scripted MultiBranch
    createMultiBranch(sampleRepo);
    // Create Declarative MultiBranch
    createMultiBranch(sampleRepo2);
    AnalyticsImpl analytics = (AnalyticsImpl) Analytics.get();
    Assert.assertNotNull(analytics);
    JobAnalytics jobAnalytics = new JobAnalytics();
    jobAnalytics.calculateAndSend();
    Assert.assertNotNull(analytics.lastReq);
    Assert.assertEquals("job_stats", analytics.lastReq.name);
    Map<String, Object> properties = analytics.lastReq.properties;
    Assert.assertEquals("singlePipelineDeclarative", 1, properties.get("singlePipelineDeclarative"));
    Assert.assertEquals("singlePipelineScripted", 1, properties.get("singlePipelineScripted"));
    Assert.assertEquals("pipelineDeclarative", 1, properties.get("pipelineDeclarative"));
    Assert.assertEquals("pipelineScripted", 1, properties.get("pipelineScripted"));
    Assert.assertEquals("freestyle", 2, properties.get("freestyle"));
    Assert.assertEquals("matrix", 1, properties.get("matrix"));
    Assert.assertEquals("other", 0, properties.get("other"));
}
Also used : JobAnalytics(io.jenkins.blueocean.service.embedded.analytics.JobAnalytics) CauseAction(hudson.model.CauseAction) WorkflowJob(org.jenkinsci.plugins.workflow.job.WorkflowJob) WorkflowRun(org.jenkinsci.plugins.workflow.job.WorkflowRun) PipelineBaseTest(io.jenkins.blueocean.rest.impl.pipeline.PipelineBaseTest) Test(org.junit.Test)

Example 77 with WorkflowRun

use of org.jenkinsci.plugins.workflow.job.WorkflowRun in project blueocean-plugin by jenkinsci.

the class PipelinePluginAnalyticsTest method createAndRunPipeline.

private void createAndRunPipeline(String jenkinsFileName) throws java.io.IOException, InterruptedException, java.util.concurrent.ExecutionException {
    // Create the pipeline and run it
    WorkflowJob scriptedSingle = createWorkflowJobWithJenkinsfile(getClass(), jenkinsFileName);
    WorkflowRun scriptedSingleRun = scriptedSingle.scheduleBuild2(0, new CauseAction()).waitForStart();
    j.waitForCompletion(scriptedSingleRun);
    // RunListeners can sometimes be executed after the run is reported as completed. This fixes a race condition.
    AnalyticsImpl analytics = (AnalyticsImpl) Analytics.get();
    Assert.assertNotNull(analytics);
    while (analytics.lastReq == null) {
        Thread.sleep(100);
    }
}
Also used : CauseAction(hudson.model.CauseAction) WorkflowJob(org.jenkinsci.plugins.workflow.job.WorkflowJob) WorkflowRun(org.jenkinsci.plugins.workflow.job.WorkflowRun)

Aggregations

WorkflowRun (org.jenkinsci.plugins.workflow.job.WorkflowRun)77 WorkflowJob (org.jenkinsci.plugins.workflow.job.WorkflowJob)72 Test (org.junit.Test)70 Map (java.util.Map)58 CpsFlowDefinition (org.jenkinsci.plugins.workflow.cps.CpsFlowDefinition)53 ImmutableMap (com.google.common.collect.ImmutableMap)45 List (java.util.List)22 ImmutableList (com.google.common.collect.ImmutableList)20 FlowNode (org.jenkinsci.plugins.workflow.graph.FlowNode)19 RunList (hudson.util.RunList)18 BranchSource (jenkins.branch.BranchSource)12 GitSCMSource (jenkins.plugins.git.GitSCMSource)12 WorkflowMultiBranchProject (org.jenkinsci.plugins.workflow.multibranch.WorkflowMultiBranchProject)12 SCMSource (jenkins.scm.api.SCMSource)11 DefaultBranchPropertyStrategy (jenkins.branch.DefaultBranchPropertyStrategy)8 CpsFlowExecution (org.jenkinsci.plugins.workflow.cps.CpsFlowExecution)7 InputAction (org.jenkinsci.plugins.workflow.support.steps.input.InputAction)6 Issue (org.jvnet.hudson.test.Issue)6 Run (hudson.model.Run)4 JSONObject (net.sf.json.JSONObject)4