Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Extensive build info #259

Merged
merged 2 commits into from
Sep 29, 2022
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
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ dependencies {
testImplementation ('ch.qos.logback:logback-classic:1.4.1')
}

ext.compatibilityVersion = JavaVersion.VERSION_1_8
ext.compatibilityVersion = JavaVersion.VERSION_11
ext.javadocPath = compatibilityVersion.isJava8() ? '' : 'en/java/'
sourceCompatibility = compatibilityVersion
targetCompatibility = compatibilityVersion
Expand Down
2 changes: 1 addition & 1 deletion src/main/docker/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
ARG jenkins_tag=2.277.4-jdk11
ARG jenkins_tag=2.303.3-lts-jdk11

FROM jenkins/jenkins:$jenkins_tag

Expand Down
1 change: 1 addition & 0 deletions src/main/docker/plugins.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@ plugins:
- artifactId: cloudbees-folder
- artifactId: configuration-as-code
- artifactId: workflow-aggregator
- artifactId: badge
17 changes: 14 additions & 3 deletions src/main/java/com/cdancy/jenkins/rest/domain/job/Action.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@

import com.google.auto.value.AutoValue;
import com.google.common.collect.ImmutableList;
import org.jclouds.javax.annotation.Nullable;
import org.jclouds.json.SerializedNames;

import java.util.List;
Expand All @@ -30,14 +31,24 @@ public abstract class Action {

public abstract List<Parameter> parameters();

@Nullable
public abstract String text();

@Nullable
public abstract String iconPath();

@Nullable
public abstract String _class();
Action() {
}

@SerializedNames({"causes", "parameters"})
public static Action create(final List<Cause> causes, final List<Parameter> parameters) {
@SerializedNames({"causes", "parameters", "text", "iconPath", "_class"})
public static Action create(final List<Cause> causes, final List<Parameter> parameters, final String text, final String iconPath, final String _class) {
return new AutoValue_Action(
causes != null ? ImmutableList.copyOf(causes) : ImmutableList.<Cause>of(),
parameters != null ? ImmutableList.copyOf(parameters) : ImmutableList.<Parameter>of());
parameters != null ? ImmutableList.copyOf(parameters) : ImmutableList.<Parameter>of(),
text, iconPath, _class
);
}
}

Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ public class JobsApiLiveTest extends BaseJenkinsApiLiveTest {

private static final String FREESTYLE_JOB_NAME = "FreeStyleSleep";
private static final String PIPELINE_JOB_NAME = "PipelineSleep";
private static final String PIPELINE_WITH_ACTION_JOB_NAME = "PipelineAction";

@Test
public void testCreateJob() {
Expand Down Expand Up @@ -249,6 +250,39 @@ public void testGetBuildParametersOfLastJob() {
assertEquals(parameters.size(), 0);
}

@Test
public void testBuildInfoActions() throws InterruptedException {
String config = payloadFromResource("/pipeline-with-action.xml");
RequestStatus createStatus = api().create(null, PIPELINE_WITH_ACTION_JOB_NAME, config);
assertTrue(createStatus.value());
IntegerResponse qId = api().build(null, PIPELINE_WITH_ACTION_JOB_NAME);
assertNotNull(qId);
assertTrue(qId.value() > 0);
QueueItem queueItem = getRunningQueueItem(qId.value());
assertNotNull(queueItem);
assertNotNull(queueItem.executable());
assertNotNull(queueItem.executable().number());
BuildInfo buildInfo = getCompletedBuild(PIPELINE_WITH_ACTION_JOB_NAME, queueItem);
assertEquals(buildInfo.result(), "SUCCESS");
System.out.println(buildInfo);
boolean found = false;
for (int idx = 0; idx < buildInfo.actions().size(); idx++) {
if (buildInfo.actions().get(idx).text() != null) {
if (buildInfo.actions().get(idx).text().equals("Hudson, we have a problem.") &&
buildInfo.actions().get(idx).iconPath().equals("error.svg") &&
buildInfo.actions().get(idx)._class().equals("com.jenkinsci.plugins.badge.action.BadgeSummaryAction")) {
found = true;
}
}
}
assertTrue(found);

// The Job is no longer needed, delete it.
RequestStatus success = api().delete(null, PIPELINE_WITH_ACTION_JOB_NAME);
assertNotNull(success);
assertTrue(success.value());
}

@Test(dependsOnMethods = "testGetBuildParametersOfLastJob")
public void testCreateJobThatAlreadyExists() {
String config = payloadFromResource("/freestyle-project.xml");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,12 @@ public void testGetBuildInfo() throws Exception {
assertNotNull(output);
assertEquals(output.fullDisplayName(), "fish #10");
assertEquals(output.artifacts().size(), 1);
assertEquals(output.actions().size(), 5);
assertEquals(output.actions().get(2).text(), "<strong>There could be HTML text here</strong>");
assertEquals(output.actions().get(2).iconPath(), "clipboard.png");
assertEquals(output.actions().get(2)._class(), "com.jenkinsci.plugins.badge.action.BadgeSummaryAction");
assertEquals(output.actions().get(3).text(), null);
assertEquals(output.actions().get(4)._class(), "org.jenkinsci.plugins.displayurlapi.actions.RunDisplayAction");
assertSent(server, "GET", "/job/fish/10/api/json");
} finally {
jenkinsApi.close();
Expand Down
11 changes: 10 additions & 1 deletion src/test/resources/build-info.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,15 @@
"userName" : "anonymous"
}
]
},
{
"text" : "<strong>There could be HTML text here</strong>",
"iconPath" : "clipboard.png",
"_class" : "com.jenkinsci.plugins.badge.action.BadgeSummaryAction"
},
{},
{
"_class" : "org.jenkinsci.plugins.displayurlapi.actions.RunDisplayAction"
}
],
"artifacts" : [
Expand Down Expand Up @@ -56,4 +65,4 @@
"fullName": "username"
}
]
}
}
12 changes: 12 additions & 0 deletions src/test/resources/pipeline-with-action.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<flow-definition plugin="workflow-job@1145.v7f2433caa07f">
<actions/>
<description/>
<keepDependencies>false</keepDependencies>
<properties/>
<definition class="org.jenkinsci.plugins.workflow.cps.CpsFlowDefinition" plugin="workflow-cps@2648.va9433432b33c">
<script>node { createSummary("error.svg").appendText("Hudson, we have a problem.", false, false, false, "red"); }</script>
<sandbox>true</sandbox>
</definition>
<triggers/>
<disabled>false</disabled>
</flow-definition>