Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 2 additions & 33 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -134,40 +134,9 @@
</dependency>
<dependency>
<groupId>org.jenkins-ci.plugins</groupId>
<artifactId>database</artifactId>
<version>1.7</version>
<artifactId>cloudbees-folder</artifactId>
<version>6.0.4</version>
<scope>test</scope>
<exclusions>
<exclusion> <!-- TODO move to bom in Jenkins core -->
<groupId>antlr</groupId>
<artifactId>antlr</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.jenkins-ci.plugins</groupId>
<artifactId>database-h2</artifactId>
<version>1.2</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>io.jenkins</groupId>
<artifactId>configuration-as-code</artifactId>
<version>${configuration-as-code.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>io.jenkins.configuration-as-code</groupId>
<artifactId>test-harness</artifactId>
<version>${configuration-as-code.version}</version>
<scope>test</scope>
<!-- TODO bump version in jcasc -->
<exclusions>
<exclusion>
<groupId>commons-validator</groupId>
<artifactId>commons-validator</artifactId>
</exclusion>
</exclusions>
</dependency>
<!-- TODO https://github.com/jenkinsci/bom/pull/294 -->
<dependency>
Expand Down
21 changes: 20 additions & 1 deletion src/main/java/io/jenkins/plugins/launchable/PropsBuilder.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
package io.jenkins.plugins.launchable;

import hudson.model.Item;
import hudson.model.Job;
import hudson.model.Run;
import net.sf.json.JSONArray;
import net.sf.json.JSONObject;

/**
Expand Down Expand Up @@ -28,6 +31,22 @@ protected JSONObject buildRunProperties() {
protected JSONObject buildJobProperties() {
return new JSONObject()
.accumulate("fullName", run.getParent().getFullName())
.accumulate("type", run.getParent().getClass().getName());
.accumulate("type", run.getParent().getClass().getName())
.accumulate("components", buildJobComponents(run.getParent()));
}

private JSONArray buildJobComponents(Item i) {
JSONArray a = new JSONArray();
while (true) {
a.add(0, new JSONObject()
.accumulate("name", i.getName())
.accumulate("type", i.getClass().getName()));

if (i.getParent() instanceof Item) {
i = (Item) i.getParent();
} else {
return a;
}
}
}
}
46 changes: 46 additions & 0 deletions src/test/java/io/jenkins/plugins/launchable/PropBuilderTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
package io.jenkins.plugins.launchable;

import com.cloudbees.hudson.plugins.folder.Folder;
import hudson.model.FreeStyleBuild;
import hudson.model.FreeStyleProject;
import net.sf.json.JSONObject;
import org.hamcrest.MatcherAssert;
import org.junit.Rule;
import org.junit.Test;
import org.jvnet.hudson.test.JenkinsRule;

import java.io.IOException;

import static org.hamcrest.CoreMatchers.*;
import static org.junit.Assert.*;

public class PropBuilderTest {
@Rule
public JenkinsRule j = new JenkinsRule();

@Test
public void basics() throws Exception {
Folder folder1 = j.jenkins.createProject(Folder.class,"foo");
FreeStyleProject project = folder1.createProject(FreeStyleProject.class,"bar");
FreeStyleBuild build = project.scheduleBuild2(0).get();

JSONObject props = new PropsBuilder<>(build).build();
MatcherAssert.assertThat(props, is(new JSONObject()
.accumulate("job", new JSONObject()
.accumulate("fullName", "foo/bar")
.accumulate("type", FreeStyleProject.class.getName())
.accumulate("components", new JSONObject[] {
new JSONObject()
.accumulate("name", "foo")
.accumulate("type", Folder.class.getName()),
new JSONObject()
.accumulate("name", "bar")
.accumulate("type", FreeStyleProject.class.getName())
}))
.accumulate("build", new JSONObject()
.accumulate("number", 1)
.accumulate("displayName", "#1")
)
));
}
}
Loading