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"));
}
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);
}
}
Aggregations