Skip to content

Commit

Permalink
Merge pull request #156 from dhurum/fix-dynamic-dls-plugins-handling-…
Browse files Browse the repository at this point in the history
…in-dsl-integration

[JENKINS-68363] - Fix dynamic DSL plugins handling in job DSL
  • Loading branch information
jtnord authored May 29, 2024
2 parents cd278e7 + e9c5969 commit f5bcee5
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -87,24 +87,20 @@ public void marshal(Object source, HierarchicalStreamWriter writer, MarshallingC

private void writeNodes(HierarchicalStreamWriter writer, List<Node> nodes) {
for (Node node : nodes) {
writer.startNode(node.name().toString());
if (node.value() instanceof Collection) {
for (Object subNode : (Collection) node.value()) {
convertNode((Node) subNode, writer);
}
} else {
writer.setValue(node.value().toString());
}
writer.endNode();
writeNode(node, writer);
}
}

private void convertNode(Node node, HierarchicalStreamWriter writer) {
private void writeNode(Node node, HierarchicalStreamWriter writer) {
writer.startNode(node.name().toString());
writeNodeAttributes(node, writer);
if (node.value() instanceof Collection) {
for (Object subNode : (Collection) node.value()) {
convertNode((Node) subNode, writer);
if (subNode instanceof Node) {
writeNode((Node) subNode, writer);
} else {
writer.setValue(subNode.toString());
}
}
} else {
writer.setValue(node.value().toString());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,4 +99,20 @@ public void testShouldGenerateTheJobWithBuildWrappers() throws Exception {
.matcher(content).find());
}

@Test
public void testShouldGenerateTheDynamicDslJob() throws Exception {
// Given
String dsl = FileUtils.readFileToString(new File("src/test/resources/dynamic-dsl-example-dsl.groovy"));
FreeStyleProject seedJob = j.createFreeStyleProject();
seedJob.getBuildersList().add(createScript(dsl));
// When
QueueTaskFuture<FreeStyleBuild> scheduleBuild2 = seedJob.scheduleBuild2(0);
j.assertBuildStatusSuccess(scheduleBuild2.get());

TopLevelItem item = j.jenkins.getItem("dynamic-dsl-test");
File config = new File(item.getRootDir(), "promotions/Development/config.xml");
String content = Files.readString(config.toPath());
assert content.contains("<javaposse.jobdsl.plugin.ExecuteDslScripts");
}

}
17 changes: 17 additions & 0 deletions src/test/resources/dynamic-dsl-example-dsl.groovy
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
freeStyleJob('dynamic-dsl-test') {
properties {
promotions {
promotion {
name('Development')
conditions {
manual('tester')
}
actions {
jobDsl {
scriptText('println test')
}
}
}
}
}
}

0 comments on commit f5bcee5

Please sign in to comment.