@Test public void testTagTranslations() throws Exception { YamlToJson underTest = new YamlToJson.Default( ImmutableList.<YamlTransform>of( new HelperTransform("!freestyle", FreeStyleProject.class), new HelperTransform("!maven", Maven.class), new HelperTransform("!git", GitSCM.class) { @Override public String construct(String value) { assertEquals("scm", value); return clazz.getName(); } }, new HelperTransform("!shell", Shell.class), new HelperTransform("!trigger", BuildTrigger.class), new HelperTransform("!mailer", Mailer.class))); for (String test : TAG_TESTS) { testOneTranslation(underTest, test); } }
@Test public void testTagTranslations() throws Exception { JsonToYaml underTest = new JsonToYaml.Default( ImmutableList.<YamlTransform>of( new HelperTransform("!freestyle", FreeStyleProject.class), new HelperTransform("!maven", Maven.class), new HelperTransform("!git", GitSCM.class) { @Override public String represent(Class clazz) { assertEquals(this.clazz, clazz); return "scm"; } @Override public String construct(String value) { assertEquals("scm", value); return this.clazz.getName(); } }, new HelperTransform("!shell", Shell.class), new HelperTransform("!trigger", BuildTrigger.class), new HelperTransform("!mailer", Mailer.class))); for (String test : TAG_TESTS) { testOneTranslation(underTest, test); } }
@Test public void testWithBuildNameSetterPlugin() throws Exception { FreeStyleProject a = jenkins.createFreeStyleProject("a"); FreeStyleProject b = jenkins.createFreeStyleProject("b"); a.getPublishersList().add(new BuildTrigger("b", false)); a.getBuildWrappersList().add(new PipelineVersionContributor(true, "1.0.0.$BUILD_NUMBER")); b.getBuildWrappersList().add(new BuildNameSetter("$PIPELINE_VERSION")); jenkins.getInstance().rebuildDependencyGraph(); jenkins.setQuietPeriod(0); jenkins.buildAndAssertSuccess(a); jenkins.waitUntilNoActivity(); assertEquals("1.0.0.1", a.getLastBuild().getDisplayName()); assertEquals("1.0.0.1", b.getLastBuild().getDisplayName()); }
@Test public void testVersionContributorNotConfigured() throws Exception { final FreeStyleProject firstProject = jenkins.createFreeStyleProject("firstProject"); final FreeStyleProject secondProject = jenkins.createFreeStyleProject("secondProject"); firstProject.getPublishersList().add(new BuildTrigger("secondProject", false)); firstProject.save(); firstProject.getBuildersList().add(new AssertNoPipelineVersion()); secondProject.getBuildersList().add(new AssertNoPipelineVersion()); jenkins.setQuietPeriod(0); jenkins.getInstance().rebuildDependencyGraph(); jenkins.buildAndAssertSuccess(firstProject); jenkins.waitUntilNoActivity(); assertNotNull(firstProject.getLastBuild()); assertNotNull(secondProject.getLastBuild()); }
@Test public void testVersionNoDisplayname() throws Exception { FreeStyleProject firstProject = jenkins.createFreeStyleProject("firstProject"); FreeStyleProject secondProject = jenkins.createFreeStyleProject("secondProject"); firstProject.getPublishersList().add(new BuildTrigger("secondProject", false)); firstProject.getBuildWrappersList().add(new PipelineVersionContributor(false, "1.0.0.${BUILD_NUMBER}")); firstProject.getBuildersList().add(new AssertPipelineVersion("1.0.0.1")); secondProject.getBuildersList().add(new AssertPipelineVersion("1.0.0.1")); jenkins.setQuietPeriod(0); jenkins.getInstance().rebuildDependencyGraph(); jenkins.buildAndAssertSuccess(firstProject); jenkins.waitUntilNoActivity(); assertNotNull(firstProject.getLastBuild()); assertNotNull(secondProject.getLastBuild()); assertEquals("#1", firstProject.getLastBuild().getDisplayName()); }
@Test public void testVersionContributorConfigured() throws Exception { FreeStyleProject firstProject = jenkins.createFreeStyleProject("firstProject"); FreeStyleProject secondProject = jenkins.createFreeStyleProject("secondProject"); firstProject.getPublishersList().add(new BuildTrigger("secondProject", false)); firstProject.getBuildWrappersList().add(new PipelineVersionContributor(true, "1.0.0.${BUILD_NUMBER}")); firstProject.getBuildersList().add(new AssertPipelineVersion("1.0.0.1")); secondProject.getBuildersList().add(new AssertPipelineVersion("1.0.0.1")); jenkins.setQuietPeriod(0); jenkins.getInstance().rebuildDependencyGraph(); jenkins.buildAndAssertSuccess(firstProject); jenkins.waitUntilNoActivity(); assertNotNull(firstProject.getLastBuild()); assertNotNull(secondProject.getLastBuild()); assertEquals("1.0.0.1", firstProject.getLastBuild().getDisplayName()); }
@Test @Issue("JENKINS-28848") public void testWithBuildNameSetterPluginAndAdditionalParameters() throws Exception { FreeStyleProject a = jenkins.createFreeStyleProject("a"); FreeStyleProject b = jenkins.createFreeStyleProject("b"); a.addProperty(new ParametersDefinitionProperty(new StringParameterDefinition("BUILD_VERSION", "DEFAULT_VALUE"))); a.getPublishersList().add(new BuildTrigger("b", false)); a.getBuildWrappersList().add(new PipelineVersionContributor(true, "1.0.0.$BUILD_NUMBER")); b.getBuildWrappersList().add(new BuildNameSetter("$PIPELINE_VERSION")); jenkins.getInstance().rebuildDependencyGraph(); jenkins.setQuietPeriod(0); jenkins.buildAndAssertSuccess(a); jenkins.waitUntilNoActivity(); assertEquals("1.0.0.1", a.getLastBuild().getDisplayName()); assertEquals("1.0.0.1", b.getLastBuild().getDisplayName()); assertEquals("1.0.0.1", a.getLastBuild().getBuildVariableResolver().resolve(PIPELINE_VERSION)); assertEquals("1.0.0.1", b.getLastBuild().getBuildVariableResolver().resolve(PIPELINE_VERSION)); }
@Test public void testGetItemsAndContains() throws Exception { final FreeStyleProject build = jenkins.createFreeStyleProject("build"); final FreeStyleProject sonar = jenkins.createFreeStyleProject("sonar"); final FreeStyleProject packaging = jenkins.createFreeStyleProject("packaging"); build.getPublishersList().add(new BuildTrigger("sonar", false)); build.getPublishersList().add(new BuildTrigger("packaging", false)); jenkins.getInstance().rebuildDependencyGraph(); List<DeliveryPipelineView.ComponentSpec> specs = new ArrayList<>(); specs.add(new DeliveryPipelineView.ComponentSpec("Comp", "build", NONE, DO_NOT_SHOW_UPSTREAM)); DeliveryPipelineView view = new DeliveryPipelineView("name"); view.setComponentSpecs(specs); jenkins.getInstance().addView(view); assertTrue(view.contains(build)); assertTrue(view.contains(sonar)); assertTrue(view.contains(packaging)); Collection<TopLevelItem> items = view.getItems(); assertEquals(3, items.size()); }
@Test public void testGetItemsAndContainsWithFolders() throws Exception { MockFolder folder = jenkins.createFolder("folder"); final FreeStyleProject build = folder.createProject(FreeStyleProject.class, "build"); final FreeStyleProject sonar = folder.createProject(FreeStyleProject.class, "sonar"); final FreeStyleProject packaging = folder.createProject(FreeStyleProject.class, "packaging"); build.getPublishersList().add(new BuildTrigger("sonar", false)); build.getPublishersList().add(new BuildTrigger("packaging", false)); jenkins.getInstance().rebuildDependencyGraph(); List<DeliveryPipelineView.ComponentSpec> specs = new ArrayList<>(); specs.add(new DeliveryPipelineView.ComponentSpec("Comp", "build", NONE, DO_NOT_SHOW_UPSTREAM)); DeliveryPipelineView view = new DeliveryPipelineView("name"); view.setComponentSpecs(specs); folder.addView(view); assertTrue(view.contains(build)); assertTrue(view.contains(sonar)); assertTrue(view.contains(packaging)); Collection<TopLevelItem> items = view.getItems(); assertEquals(3, items.size()); }
@Test public void testGetPipelineViewWithLastJobProvided() throws Exception { FreeStyleProject build = jenkins.createFreeStyleProject("build"); FreeStyleProject test = jenkins.createFreeStyleProject("test"); FreeStyleProject deploy = jenkins.createFreeStyleProject("deploy"); build.getPublishersList().add(new BuildTrigger(test.getName(), false)); test.getPublishersList().add(new BuildTrigger(deploy.getName(), false)); jenkins.getInstance().rebuildDependencyGraph(); jenkins.buildAndAssertSuccess(build); jenkins.waitUntilNoActivity(); List<DeliveryPipelineView.ComponentSpec> specs = new ArrayList<>(); specs.add(new DeliveryPipelineView.ComponentSpec("Comp", "build", "test", DO_NOT_SHOW_UPSTREAM)); DeliveryPipelineView view = new DeliveryPipelineView("Pipeline"); view.setComponentSpecs(specs); view.setSorting(NameComparator.class.getName()); jenkins.getInstance().addView(view); view.getPipelines(); assertNull(view.getError()); }
@Test public void testGetItems() throws IOException { final FreeStyleProject firstJob = jenkins.createFreeStyleProject("Project1"); final FreeStyleProject secondJob = jenkins.createFreeStyleProject("Project2"); final FreeStyleProject thirdJob = jenkins.createFreeStyleProject("Project3"); firstJob.getPublishersList().add((new BuildTrigger(secondJob.getName(), true))); jenkins.getInstance().rebuildDependencyGraph(); DeliveryPipelineView pipeline = new DeliveryPipelineView("Pipeline"); List<DeliveryPipelineView.ComponentSpec> componentSpecs = new ArrayList<>(); componentSpecs.add(new DeliveryPipelineView.ComponentSpec("Spec", firstJob.getName(), NONE, DO_NOT_SHOW_UPSTREAM)); pipeline.setComponentSpecs(componentSpecs); jenkins.getInstance().addView(pipeline); Collection<TopLevelItem> jobs = pipeline.getItems(); assertTrue(jobs.contains(firstJob)); assertTrue(jobs.contains(secondJob)); assertFalse(jobs.contains(thirdJob)); }
@Test public void testResolveWithSimpleTrigger() throws Exception { FreeStyleProject a = jenkins.createFreeStyleProject("a"); jenkins.createFreeStyleProject("b"); jenkins.createFreeStyleProject("c"); a.getPublishersList().add(new BuildTrigger("b", false)); JobPropertyImpl property = new JobPropertyImpl(a); PromotionProcess process = property.addProcess("process"); process.conditions.add(new DownstreamPassCondition("b", false)); process.getBuildSteps().add(new BuildTrigger("c", false)); process.save(); a.addProperty(property); jenkins.getInstance().rebuildDependencyGraph(); PromotedBuildRelationshipResolver resolver = new PromotedBuildRelationshipResolver(); List<AbstractProject> projects = resolver.getDownstreamProjects(a); assertEquals(1, projects.size()); }
@Test public void testResolveWithParamTrigger() throws Exception { FreeStyleProject a = jenkins.createFreeStyleProject("a"); jenkins.createFreeStyleProject("b"); jenkins.createFreeStyleProject("c"); a.getPublishersList().add(new BuildTrigger("b", false)); JobPropertyImpl property = new JobPropertyImpl(a); PromotionProcess process = property.addProcess("process"); process.conditions.add(new DownstreamPassCondition("b", false)); process.getBuildSteps().add(new hudson.plugins.parameterizedtrigger.BuildTrigger(new BuildTriggerConfig("c", ResultCondition.ALWAYS))); process.save(); a.addProperty(property); jenkins.getInstance().rebuildDependencyGraph(); PromotedBuildRelationshipResolver resolver = new PromotedBuildRelationshipResolver(); List<AbstractProject> projects = resolver.getDownstreamProjects(a); assertEquals(1, projects.size()); }
@Test @Issue("JENKINS-28347") public void testResolveWithBuildTrigger() throws Exception { FreeStyleProject a = jenkins.createFreeStyleProject("a"); jenkins.createFreeStyleProject("b"); jenkins.createFreeStyleProject("c"); a.getPublishersList().add(new BuildTrigger("b", false)); JobPropertyImpl property = new JobPropertyImpl(a); PromotionProcess process = property.addProcess("process"); process.conditions.add(new DownstreamPassCondition("b", false)); process.getBuildSteps().add(new hudson.plugins.parameterizedtrigger.TriggerBuilder(new BlockableBuildTriggerConfig("b", new BlockingBehaviour(Result.FAILURE, Result.UNSTABLE, Result.FAILURE), null))); process.save(); a.addProperty(property); jenkins.getInstance().rebuildDependencyGraph(); PromotedBuildRelationshipResolver resolver = new PromotedBuildRelationshipResolver(); List<AbstractProject> projects = resolver.getDownstreamProjects(a); assertEquals(1, projects.size()); }
@SuppressWarnings("deprecation") @Test public void testFirstLastProjects() throws Exception { FreeStyleProject projectA = jenkins.createFreeStyleProject("projectA"); FreeStyleProject projectB = jenkins.createFreeStyleProject("projectB"); FreeStyleProject projectC = jenkins.createFreeStyleProject("projectC"); FreeStyleProject projectD = jenkins.createFreeStyleProject("projectD"); projectA.getPublishersList().add(new BuildTrigger(projectB.getName(), true)); projectB.getPublishersList().add(new BuildTrigger(projectC.getName(), true)); projectC.getPublishersList().add(new BuildTrigger(projectD.getName(), true)); jenkins.getInstance().rebuildDependencyGraph(); jenkins.getInstance().getExtensionList(RelationshipResolver.class).add(new ProjectRelationshipResolver()); Map<String, AbstractProject<?, ?>> projects = ProjectUtil.getAllDownstreamProjects(projectB, projectC); assertEquals(2, projects.size()); assertTrue(!projects.containsKey("projectA")); assertTrue(projects.containsKey("projectB")); assertTrue(projects.containsKey("projectC")); assertTrue(!projects.containsKey("projectD")); }
@Test public void testFirstUpstreamBuildFirstProjectHasUpstreamJob() throws Exception { final FreeStyleProject upstream = jenkins.createFreeStyleProject("upstream"); final FreeStyleProject build = jenkins.createFreeStyleProject("build"); final FreeStyleProject pack = jenkins.createFreeStyleProject("package"); upstream.getPublishersList().add(new BuildTrigger("build", false)); build.getPublishersList().add(new BuildTrigger("package", false)); jenkins.getInstance().rebuildDependencyGraph(); jenkins.setQuietPeriod(0); jenkins.buildAndAssertSuccess(upstream); jenkins.waitUntilNoActivity(); assertNotNull(upstream.getLastBuild()); assertNotNull(build.getLastBuild()); assertNotNull(pack.getLastBuild()); assertEquals(build.getLastBuild(), BuildUtil.getFirstUpstreamBuild(pack.getLastBuild(), build)); }
@Test public void testExtractSimpleForkJoinPipeline() throws Exception { FreeStyleProject build = jenkins.createFreeStyleProject("build"); build.addProperty(new PipelineProperty(null, "build", "")); FreeStyleProject deploy1 = jenkins.createFreeStyleProject("deploy1"); deploy1.addProperty(new PipelineProperty(null, "CI", "")); FreeStyleProject deploy2 = jenkins.createFreeStyleProject("deploy2"); deploy2.addProperty(new PipelineProperty(null, "CI", "")); FreeStyleProject deploy3 = jenkins.createFreeStyleProject("deploy3"); deploy3.addProperty(new PipelineProperty(null, "QA", "")); build.getPublishersList().add(new BuildTrigger("deploy1,deploy2", false)); deploy1.getPublishersList().add(new BuildTrigger("deploy3", false)); deploy2.getPublishersList().add(new BuildTrigger("deploy3", false)); jenkins.getInstance().rebuildDependencyGraph(); Pipeline pipeline = Pipeline.extractPipeline("Pipeline", build); assertEquals(3, pipeline.getStages().size()); assertEquals(1, pipeline.getStages().get(2).getTasks().size()); assertEquals("deploy3", pipeline.getStages().get(2).getTasks().get(0).getName()); }
@Test public void testExtractPipelineWithSubProjects() throws Exception { FreeStyleProject build = jenkins.createFreeStyleProject("build"); build.addProperty(new PipelineProperty("Build", "Build", "")); FreeStyleProject sonar = jenkins.createFreeStyleProject("sonar"); sonar.addProperty(new PipelineProperty("Sonar", "Build", "")); FreeStyleProject deploy = jenkins.createFreeStyleProject("deploy"); deploy.addProperty(new PipelineProperty("Deploy", "QA", "")); build.getBuildersList().add( new TriggerBuilder( new BlockableBuildTriggerConfig("sonar", new BlockingBehaviour("never", "never", "never"), null))); build.getPublishersList().add(new BuildTrigger("deploy", false)); jenkins.getInstance().rebuildDependencyGraph(); Pipeline pipeline = Pipeline.extractPipeline("Pipeline", build); assertEquals(2, pipeline.getStages().size()); assertEquals(2, pipeline.getStages().get(0).getTasks().size()); assertEquals(1, pipeline.getStages().get(1).getTasks().size()); }
@Test public void testPipelineLatestDownstreamIsDisabled() throws Exception { FreeStyleProject build = jenkins.createFreeStyleProject("build"); FreeStyleProject disabled = jenkins.createFreeStyleProject("disabled"); disabled.makeDisabled(true); build.getPublishersList().add(new BuildTrigger("disabled", false)); jenkins.getInstance().rebuildDependencyGraph(); jenkins.buildAndAssertSuccess(build); jenkins.waitUntilNoActivity(); Pipeline pipeline = Pipeline.extractPipeline("Pipeline", build); Pipeline latest = createPipelineLatest(pipeline, jenkins.getInstance()); assertNotNull(latest); assertEquals(2, latest.getStages().size()); assertEquals("SUCCESS", latest.getStages().get(0).getTasks().get(0).getStatus().toString()); assertEquals("DISABLED", latest.getStages().get(1).getTasks().get(0).getStatus().toString()); }
@Test public void testFirstUpstreamBuildFirstProjectHasJustOneUpstreamJob() throws Exception { StaplerRequest request = Mockito.mock(StaplerRequest.class); final FreeStyleProject upstream = jenkins.createFreeStyleProject("upstream"); final FreeStyleProject build = jenkins.createFreeStyleProject("build"); upstream.getPublishersList().add(new BuildTrigger("build", false)); jenkins.getInstance().rebuildDependencyGraph(); jenkins.buildAndAssertSuccess(upstream); jenkins.waitUntilNoActivity(); assertNotNull(upstream.getLastBuild()); assertNotNull(build.getLastBuild()); assertEquals(build.getLastBuild(), BuildUtil.getFirstUpstreamBuild(build.getLastBuild(), build)); Pipeline pipeline = Pipeline.extractPipeline("Pipeline", build); Component component = new Component("Component", "build", null, false, 3, PAGING_DISABLED, 1); List<Pipeline> pipelines = pipeline.createPipelineLatest(1, Jenkins.getInstance(), PAGING_DISABLED, SHOW_CHANGES, component); assertEquals(1, pipelines.size()); assertEquals(1, pipelines.get(0).getTriggeredBy().size()); assertEquals(TriggerCause.TYPE_UPSTREAM, pipelines.get(0).getTriggeredBy().get(0).getType()); }
@Test public void testForkJoin() throws Exception { FreeStyleProject projectA = jenkins.createFreeStyleProject("A"); FreeStyleProject projectB = jenkins.createFreeStyleProject("B"); FreeStyleProject projectC = jenkins.createFreeStyleProject("C"); FreeStyleProject projectD = jenkins.createFreeStyleProject("D"); projectA.getPublishersList().add(new BuildTrigger("B,C", false)); projectB.getPublishersList().add(new BuildTrigger("D", false)); projectC.getPublishersList().add(new BuildTrigger("D", false)); projectD.getPublishersList().add( new JoinTrigger(new DescribableList<>(Saveable.NOOP), "", false)); jenkins.getInstance().rebuildDependencyGraph(); Pipeline prototype = Pipeline.extractPipeline("ForkJoin", projectA); assertNotNull(prototype); assertEquals(4, prototype.getStages().size()); assertEquals(0, prototype.getStages().get(0).getColumn()); assertEquals(0, prototype.getStages().get(0).getRow()); assertEquals(1, prototype.getStages().get(1).getColumn()); assertEquals(0, prototype.getStages().get(1).getRow()); assertEquals(2, prototype.getStages().get(2).getColumn()); assertEquals(0, prototype.getStages().get(2).getRow()); assertEquals(1, prototype.getStages().get(3).getColumn()); assertEquals(1, prototype.getStages().get(3).getRow()); }
@Test public void testBindJob_FullJob() throws Exception { JSONObject json = (JSONObject) JSONSerializer.toJSON(EMPTY_JSON); // TODO(mattmoor): The logic in hudson.scm.SCMS uses the index of the SCM // among the collection of compatible SCMS for the given project to // determine which class to bind instead of relying on the '$class' field. // I have prototyped a fix for this, but until it can be pushed back, // we cannot test this. // JSONObject scm = (JSONObject) JSONSerializer.toJSON(GITSCM_JSON); // json.put("scm", scm); JSONArray builders = (JSONArray) JSONSerializer.toJSON(BUILDERS2_JSON); json.put("builder", builders); JSONArray publishers = (JSONArray) JSONSerializer.toJSON(PUBLISHERS_JSON); json.put("publisher", publishers); Job job = underTest.bindJob(Jenkins.getInstance(), NAME, json); assertNotNull(job); assertThat(job, instanceOf(FreeStyleProject.class)); assertEquals(NAME, job.getName()); FreeStyleProject project = (FreeStyleProject) job; assertEquals(1, project.getBuilders().size()); assertThat(project.getBuilders().get(0), instanceOf(Maven.class)); // NOTE: getPublishers returns a Map, but the above returns a list assertEquals(1, project.getPublishers().values().size()); assertThat(project.getPublishers().values().toArray()[0], instanceOf(BuildTrigger.class)); }
@Test @Issue("JENKINS-22658") public void testRecursiveStages() throws Exception { FreeStyleProject projectA = jenkins.createFreeStyleProject("A"); projectA.addProperty(new PipelineProperty("A", "A", "")); FreeStyleProject projectB = jenkins.createFreeStyleProject("B"); projectB.addProperty(new PipelineProperty("B", "B", "")); FreeStyleProject projectC = jenkins.createFreeStyleProject("C"); projectC.addProperty(new PipelineProperty("C", "C", "")); FreeStyleProject projectD = jenkins.createFreeStyleProject("D"); projectD.addProperty(new PipelineProperty("D", "B", "")); projectA.getPublishersList().add(new hudson.plugins.parameterizedtrigger.BuildTrigger( new BuildTriggerConfig("B", ResultCondition.SUCCESS, new ArrayList<>()))); projectB.getPublishersList().add(new hudson.plugins.parameterizedtrigger.BuildTrigger( new BuildTriggerConfig("C", ResultCondition.SUCCESS, new ArrayList<>()))); projectC.getPublishersList().add(new hudson.plugins.parameterizedtrigger.BuildTrigger( new BuildTriggerConfig("D", ResultCondition.SUCCESS, new ArrayList<>()))); jenkins.getInstance().rebuildDependencyGraph(); DeliveryPipelineView view = new DeliveryPipelineView("Pipeline"); List<DeliveryPipelineView.ComponentSpec> componentSpecs = new ArrayList<>(); componentSpecs.add(new DeliveryPipelineView.ComponentSpec("Comp", "A", NONE, DO_NOT_SHOW_UPSTREAM)); view.setComponentSpecs(componentSpecs); jenkins.getInstance().addView(view); List<Component> components = view.getPipelines(); assertEquals(0, components.size()); assertNotNull(view.getError()); assertTrue(view.getError().startsWith("Circular dependencies between stages: ")); assertTrue(view.getError().contains("B")); assertTrue(view.getError().contains("C")); }
@Test public void testRebuild() throws Exception { FreeStyleProject projectA = jenkins.createFreeStyleProject("A"); FreeStyleProject projectB = jenkins.createFreeStyleProject("B"); projectB.addProperty(new ParametersDefinitionProperty( new StringParameterDefinition("BUILD_VERSION", "DEFAULT_VALUE"))); projectA.getPublishersList().add( new hudson.plugins.parameterizedtrigger.BuildTrigger( new BuildTriggerConfig("b", ResultCondition.SUCCESS, new PredefinedBuildParameters("VERSION=$BUILD_NUMBER")))); jenkins.getInstance().rebuildDependencyGraph(); DeliveryPipelineView view = new DeliveryPipelineView("Pipeline"); jenkins.getInstance().addView(view); jenkins.buildAndAssertSuccess(projectA); jenkins.waitUntilNoActivity(); assertNotNull(projectA.getLastBuild()); assertNotNull(projectB.getLastBuild()); final AbstractBuild<?, ?> b1 = projectB.getLastBuild(); view.triggerRebuild("B", "1"); jenkins.waitUntilNoActivity(); assertEquals(2, projectB.getLastBuild().getNumber()); assertEqualsList(b1.getActions(ParametersAction.class), projectB.getLastBuild().getActions(ParametersAction.class)); }
@Test public void testHasDownstream() throws Exception { final FreeStyleProject projectA = jenkins.createFreeStyleProject("a"); final FreeStyleProject projectB = jenkins.createFreeStyleProject("b"); projectA.getPublishersList().add(new BuildTrigger("b", false)); jenkins.getInstance().rebuildDependencyGraph(); RelationshipResolver resolver = new ProjectRelationshipResolver(); List<AbstractProject> downStreams = resolver.getDownstreamProjects(projectA); assertFalse(downStreams.isEmpty()); assertEquals(projectB, downStreams.get(0)); }
@Test public void testRecursiveProjects() throws Exception { FreeStyleProject projectA = jenkins.createFreeStyleProject("projectA"); FreeStyleProject projectB = jenkins.createFreeStyleProject("projectB"); projectA.getPublishersList().add(new BuildTrigger(projectB.getName(), true)); projectB.getPublishersList().add(new BuildTrigger(projectA.getName(), true)); jenkins.getInstance().rebuildDependencyGraph(); assertEquals(projectA.getUpstreamProjects().get(0), projectB); assertEquals(projectB.getUpstreamProjects().get(0), projectA); // If there is a cycle dependency, then a stack overflow will be thrown here. ProjectUtil.getAllDownstreamProjects(projectA, null); }
@Test public void testGetStartUpstreamsSimple() throws Exception { FreeStyleProject projectA = jenkins.createFreeStyleProject("A"); FreeStyleProject projectB = jenkins.createFreeStyleProject("B"); FreeStyleProject projectC = jenkins.createFreeStyleProject("C"); projectA.getPublishersList().add(new BuildTrigger(projectC.getName(), true)); projectB.getPublishersList().add(new BuildTrigger(projectC.getName(), true)); jenkins.getInstance().rebuildDependencyGraph(); List<AbstractProject> upstrems = ProjectUtil.getStartUpstreams(projectC); assertEquals(2, upstrems.size()); }
@Test public void testIsManualTriggerMultipleUpstreams() throws Exception { final FreeStyleProject projectA = jenkins.createFreeStyleProject("a"); final FreeStyleProject projectB = jenkins.createFreeStyleProject("b"); final FreeStyleProject projectC = jenkins.createFreeStyleProject("c"); projectA.getPublishersList().add(new BuildTrigger("c", true)); projectB.getPublishersList().add(new BuildPipelineTrigger("c", null)); jenkins.getInstance().rebuildDependencyGraph(); assertTrue(new BPPManualTriggerResolver().isManualTrigger(projectC)); }
@Test public void testTriggerNewParameterizedPipeline() throws Exception { FreeStyleProject start = jenkins.createFreeStyleProject("Start"); start.addProperty(new ParametersDefinitionProperty( new StringParameterDefinition("key2", "value2") )); jenkins.createFreeStyleProject("End"); start.getPublishersList().add(new BuildTrigger("End", true)); jenkins.getInstance().rebuildDependencyGraph(); DeliveryPipelineView view = new DeliveryPipelineView("Pipeline"); List<DeliveryPipelineView.ComponentSpec> specs = new ArrayList<>(); specs.add(new DeliveryPipelineView.ComponentSpec("Component", "Start", NONE, DO_NOT_SHOW_UPSTREAM)); view.setComponentSpecs(specs); view.setAllowPipelineStart(true); jenkins.getInstance().addView(view); DeliveryPipelinePage page = new DeliveryPipelinePage(webDriver, jenkins.getURL().toExternalForm(), "view/Pipeline"); page.open(); page.triggerNewParameterizedPipelineBuild("0"); jenkins.waitUntilNoActivity(); assertNotNull(start.getLastBuild()); }
@Test public void testTriggerNewPipeline() throws Exception { FreeStyleProject start = jenkins.createFreeStyleProject("Start"); jenkins.createFreeStyleProject("End"); start.getPublishersList().add(new BuildTrigger("End", true)); jenkins.getInstance().rebuildDependencyGraph(); DeliveryPipelineView view = new DeliveryPipelineView("Pipeline"); List<DeliveryPipelineView.ComponentSpec> specs = new ArrayList<>(); specs.add(new DeliveryPipelineView.ComponentSpec("Component", "Start", NONE, DO_NOT_SHOW_UPSTREAM)); view.setComponentSpecs(specs); view.setAllowPipelineStart(true); jenkins.getInstance().addView(view); DeliveryPipelinePage page = new DeliveryPipelinePage(webDriver, jenkins.getURL().toExternalForm(), "view/Pipeline"); page.open(); page.triggerNewPipelineBuild("0"); jenkins.waitUntilNoActivity(); assertNotNull(start.getLastBuild()); }
@Test public void testTriggerNewPipelineFolders() throws Exception { Folder folder = jenkins.getInstance().createProject(Folder.class, "Folder"); assertNotNull(folder); FreeStyleProject start = jenkins.createFreeStyleProject("Start"); folder.createProject(FreeStyleProject.class, "End"); start.getPublishersList().add(new BuildTrigger("End", true)); jenkins.getInstance().rebuildDependencyGraph(); DeliveryPipelineView view = new DeliveryPipelineView("Pipeline"); List<DeliveryPipelineView.ComponentSpec> specs = new ArrayList<>(); specs.add(new DeliveryPipelineView.ComponentSpec("Component", "Start", NONE, DO_NOT_SHOW_UPSTREAM)); view.setComponentSpecs(specs); view.setAllowPipelineStart(true); folder.addView(view); DeliveryPipelinePage page = new DeliveryPipelinePage(webDriver, jenkins.getURL().toExternalForm(), "job/Folder/view/Pipeline"); page.open(); page.triggerNewPipelineBuild("0"); jenkins.waitUntilNoActivity(); assertNotNull(start.getLastBuild()); }
@Test @Issue("JENKINS-39856") public void jsPlumbShouldNotLeakMemoryOnDeliveryPipelinePage() throws Exception { FreeStyleProject start = jenkins.createFreeStyleProject("A"); jenkins.createFreeStyleProject("B"); start.getPublishersList().add(new BuildTrigger("B", true)); jenkins.getInstance().rebuildDependencyGraph(); DeliveryPipelineView view = new DeliveryPipelineView("Pipeline"); List<DeliveryPipelineView.ComponentSpec> specs = new ArrayList<>(); specs.add(new DeliveryPipelineView.ComponentSpec("Component", "A", NONE, DO_NOT_SHOW_UPSTREAM)); view.setComponentSpecs(specs); view.setAllowPipelineStart(true); jenkins.getInstance().addView(view); DeliveryPipelinePage page = new DeliveryPipelinePage(webDriver, jenkins.getURL().toExternalForm(), "view/Pipeline"); page.open(); String result = page.getJsPlumbUtilityVariable(); jenkins.waitUntilNoActivity(); assertNotNull(result); assertEquals("1", result); }
@Test @Issue("JENKINS-39856") public void jsPlumbShouldNotLeakMemoryOnDeliveryPipelineDashboardPortlet() throws Exception { FreeStyleProject projectA = jenkins.createFreeStyleProject("A"); jenkins.createFreeStyleProject("B"); projectA.getPublishersList().add(new BuildTrigger("B", true)); FreeStyleProject projectC = jenkins.createFreeStyleProject("C"); jenkins.createFreeStyleProject("D"); projectC.getPublishersList().add(new BuildTrigger("D", true)); jenkins.getInstance().rebuildDependencyGraph(); Dashboard view = new Dashboard("Dashboard"); jenkins.getInstance().addView(view); view.updateByXml(new StreamSource(GuiFunctionalIT.class.getResourceAsStream( "/se/diabol/jenkins/pipeline/functionaltest/GuiFunctionalIT/DashboardViewPage.xml"))); view.save(); DeliveryPipelinePage page = new DeliveryPipelinePage(webDriver, jenkins.getURL().toExternalForm(), "view/Dashboard"); page.open(); String result = page.getJsPlumbUtilityVariable(); jenkins.waitUntilNoActivity(); assertNotNull(result); assertEquals("2", result); }
@Test public void getPipelineLatestWithDifferentFolders() throws Exception { MockFolder folder1 = jenkins.createFolder("folder1"); MockFolder folder2 = jenkins.createFolder("folder2"); final FreeStyleProject job1 = folder1.createProject(FreeStyleProject.class, "job1"); final FreeStyleProject job2 = folder2.createProject(FreeStyleProject.class, "job2"); job1.getPublishersList().add(new BuildTrigger("folder2/job2", false)); jenkins.getInstance().rebuildDependencyGraph(); jenkins.setQuietPeriod(0); Pipeline prototype = Pipeline.extractPipeline("Folders", job1); assertNotNull(prototype); jenkins.buildAndAssertSuccess(job1); jenkins.waitUntilNoActivity(); assertNotNull(job1.getLastBuild()); assertNotNull(job2.getLastBuild()); Pipeline pipeline = createPipelineLatest(prototype, folder1); assertNotNull(pipeline); assertEquals(2, pipeline.getStages().size()); assertEquals("folder1/job1", pipeline.getStages().get(0).getTasks().get(0).getId()); assertEquals("folder2/job2", pipeline.getStages().get(1).getTasks().get(0).getId()); assertEquals(0, pipeline.getStages().get(0).getColumn()); assertEquals(1, pipeline.getStages().get(1).getColumn()); }
@Test public void getPipelineLatestWithSameFolders() throws Exception { MockFolder folder1 = jenkins.createFolder("folder1"); final FreeStyleProject job1 = folder1.createProject(FreeStyleProject.class, "job1"); final FreeStyleProject job2 = folder1.createProject(FreeStyleProject.class, "job2"); job1.getPublishersList().add(new BuildTrigger("folder1/job2", false)); jenkins.getInstance().rebuildDependencyGraph(); jenkins.setQuietPeriod(0); Pipeline prototype = Pipeline.extractPipeline("Folders", job1); assertNotNull(prototype); jenkins.buildAndAssertSuccess(job1); jenkins.waitUntilNoActivity(); assertNotNull(job1.getLastBuild()); assertNotNull(job2.getLastBuild()); Pipeline pipeline = createPipelineLatest(prototype, folder1); assertNotNull(pipeline); assertEquals(2, pipeline.getStages().size()); assertEquals("folder1/job1", pipeline.getStages().get(0).getTasks().get(0).getId()); assertEquals("folder1/job2", pipeline.getStages().get(1).getTasks().get(0).getId()); assertTrue(pipeline.getStages().get(0).getTasks().get(0).getStatus().isSuccess()); assertTrue(pipeline.getStages().get(1).getTasks().get(0).getStatus().isSuccess()); }
@Test public void getPipelineLatestWithNestedFolders() throws Exception { MockFolder folder1 = jenkins.createFolder("folder1"); MockFolder folder2 = folder1.createProject(MockFolder.class, "subfolder"); final FreeStyleProject job1 = folder2.createProject(FreeStyleProject.class, "job1"); final FreeStyleProject job2 = folder1.createProject(FreeStyleProject.class, "job2"); job1.getPublishersList().add(new BuildTrigger("folder1/job2", false)); jenkins.getInstance().rebuildDependencyGraph(); jenkins.setQuietPeriod(0); Pipeline prototype = Pipeline.extractPipeline("Folders", job1); assertNotNull(prototype); jenkins.buildAndAssertSuccess(job1); jenkins.waitUntilNoActivity(); assertNotNull(job1.getLastBuild()); assertNotNull(job2.getLastBuild()); Pipeline pipeline = createPipelineLatest(prototype, folder1); assertNotNull(pipeline); assertEquals(2, pipeline.getStages().size()); assertEquals("folder1/subfolder/job1", pipeline.getStages().get(0).getTasks().get(0).getId()); assertEquals("folder1/job2", pipeline.getStages().get(1).getTasks().get(0).getId()); assertTrue(pipeline.getStages().get(0).getTasks().get(0).getStatus().isSuccess()); assertTrue(pipeline.getStages().get(1).getTasks().get(0).getStatus().isSuccess()); }
@Test @Issue("JENKINS-30043") public void testSubProjectsFirst() throws Exception { FreeStyleProject jobA = jenkins.createFreeStyleProject("Job A"); jobA.addProperty(new PipelineProperty(null, "Stage", null)); FreeStyleProject util1 = jenkins.createFreeStyleProject("Job Util 1"); util1.addProperty(new PipelineProperty(null, "Stage", null)); FreeStyleProject util2 = jenkins.createFreeStyleProject("Job Util 2"); util2.addProperty(new PipelineProperty(null, "Stage", null)); FreeStyleProject jobC = jenkins.createFreeStyleProject("Job C"); jobC.addProperty(new PipelineProperty(null, "Stage", null)); jobA.getBuildersList().add(new TriggerBuilder( new BlockableBuildTriggerConfig("Job Util 1", new BlockingBehaviour("never", "never", "never"), null))); jobA.getBuildersList().add(new TriggerBuilder( new BlockableBuildTriggerConfig("Job Util 2", new BlockingBehaviour("never", "never", "never"), null))); jobA.getPublishersList().add(new hudson.plugins.parameterizedtrigger.BuildTrigger( new BuildTriggerConfig("Job C", ResultCondition.SUCCESS, new ArrayList<>()))); jenkins.getInstance().rebuildDependencyGraph(); Pipeline pipeline = Pipeline.extractPipeline("Pipeline", jobA); assertEquals("Job A", pipeline.getStages().get(0).getTasks().get(0).getId()); assertEquals("Job Util 1", pipeline.getStages().get(0).getTasks().get(1).getId()); assertEquals("Job Util 2", pipeline.getStages().get(0).getTasks().get(2).getId()); assertEquals("Job C", pipeline.getStages().get(0).getTasks().get(3).getId()); }
@Test @Issue("JENKINS-28845") public void testIsRebuildableNoPermission() throws Exception { FreeStyleProject a = jenkins.createFreeStyleProject("A"); FreeStyleProject b = jenkins.createFreeStyleProject("B"); b.getBuildersList().add(new FailureBuilder()); a.getPublishersList().add(new BuildTrigger("B", false)); jenkins.setQuietPeriod(0); jenkins.getInstance().rebuildDependencyGraph(); FreeStyleBuild firstBuild = jenkins.buildAndAssertSuccess(a); jenkins.waitUntilNoActivity(); assertNotNull(b.getLastBuild()); assertTrue(b.getLastBuild().getResult().equals(Result.FAILURE)); jenkins.getInstance().setSecurityRealm(jenkins.createDummySecurityRealm()); GlobalMatrixAuthorizationStrategy gmas = new GlobalMatrixAuthorizationStrategy(); gmas.add(Permission.READ, "devel"); jenkins.getInstance().setAuthorizationStrategy(gmas); SecurityContext oldContext = ACL.impersonate(User.get("devel").impersonate()); Task prototype = Task.getPrototypeTask(b, false); Task task = prototype.getLatestTask(jenkins.getInstance(), firstBuild); assertNotNull(task); assertFalse(task.isRebuildable()); SecurityContextHolder.setContext(oldContext); }
private void testSimplePipelineTaskNames(String taskNameA, String taskNameB, String expectedBeforeA, String expectedBeforeB, String expectedAfterA, String expectedAfterB) throws Exception { FreeStyleProject a = jenkins.createFreeStyleProject("A"); FreeStyleProject b = jenkins.createFreeStyleProject("B"); a.addProperty(new PipelineProperty(taskNameA, "Stage Build", null)); b.addProperty(new PipelineProperty(taskNameB, "Stage Deploy", null)); a.getPublishersList().add(new BuildTrigger("B", false)); jenkins.setQuietPeriod(0); jenkins.getInstance().rebuildDependencyGraph(); Task taskA = Task.getPrototypeTask(a, true).getLatestTask(jenkins.getInstance(), null); Task taskB = Task.getPrototypeTask(b, false).getLatestTask(jenkins.getInstance(), null); assertEquals(expectedBeforeA, taskA.getName()); assertEquals(expectedBeforeB, taskB.getName()); FreeStyleBuild firstBuild = jenkins.buildAndAssertSuccess(a); jenkins.waitUntilNoActivity(); taskA = Task.getPrototypeTask(a, true).getLatestTask(jenkins.getInstance(), firstBuild); taskB = Task.getPrototypeTask(b, false).getLatestTask(jenkins.getInstance(), firstBuild); assertEquals(expectedAfterA, taskA.getName()); assertEquals(expectedAfterB, taskB.getName()); }
@Test public void testIsManualTriggerAndResolveManualStep() throws Exception { final FreeStyleProject upstream = jenkins.createFreeStyleProject("upstream"); final FreeStyleProject downstreamManual = jenkins.createFreeStyleProject("downstreamManual"); upstream.getPublishersList().add(new BuildPipelineTrigger("downstreamManual", null)); final FreeStyleProject projectA = jenkins.createFreeStyleProject("a"); final FreeStyleProject projectB = jenkins.createFreeStyleProject("b"); projectA.getPublishersList().add(new BuildTrigger("b", false)); jenkins.getInstance().rebuildDependencyGraph(); assertTrue(ManualStep.isManualTrigger(downstreamManual)); assertFalse(ManualStep.isManualTrigger(upstream)); assertFalse(ManualStep.isManualTrigger(projectA)); assertFalse(ManualStep.isManualTrigger(projectB)); assertNull(ManualStep.resolveManualStep(projectA)); assertNull(ManualStep.resolveManualStep(projectB)); assertNull(ManualStep.resolveManualStep(upstream)); ManualStep step = ManualStep.resolveManualStep(downstreamManual); assertNotNull(step); assertNull(step.getUpstreamId()); assertFalse(step.isEnabled()); assertTrue(step.isPermission()); assertNull(step.getPossibleVersions()); assertEquals("downstreamManual", step.getUpstreamProject()); }