Skip to content

Commit 3dd41b1

Browse files
authored
JENKINS-69312 JiraTestResultReporter plugin does not show plus button to create an issue (#211)
* - fix for https://issues.jenkins.io/browse/JENKINS-69312 and dup https://issues.jenkins.io/browse/JENKINS-67777 with an additional checkbox to enable manual linking * avoid potentially problematic resorting of members, see #211 (review)
1 parent 21a9935 commit 3dd41b1

File tree

6 files changed

+55
-12
lines changed

6 files changed

+55
-12
lines changed

README.md

+3
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,7 @@ junit (
9090
autoUnlinkIssue: false,
9191
additionalAttachments: false,
9292
overrideResolvedIssues: false,
93+
manualAddIssue: false,
9394
)
9495
]
9596
)
@@ -123,6 +124,8 @@ If you check the **Auto unlink issues when test passes** check box, this plugin
123124

124125
If you check the **Auto override resolved issues** check box, this plugin will create new issues automatically for failing tests that are linked to already resolved issues.
125126

127+
If you check the **Manually link or raise issues** check box, this plugin will allow to manually link or create issues to the failing tests in new builds also if auto raise is not enabled.
128+
126129
![image of job config settings](img/job-config1.png)
127130

128131
Only after configuring the fields above, if you want you can override the **Summary** and **Description** values by clicking the **Advanced** button.

src/main/java/org/jenkinsci/plugins/JiraTestResultReporter/JiraTestDataPublisher.java

+15-3
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,10 @@ public boolean getOverrideResolvedIssues() {
138138
return JobConfigMapping.getInstance().getOverrideResolvedIssues(getJobName());
139139
}
140140

141+
public boolean getManualAddIssue() {
142+
return JobConfigMapping.getInstance().getManualAddIssue(getJobName());
143+
}
144+
141145
/**
142146
* Getter for list of attachments by test method identified by its classname and name
143147
* @param className
@@ -187,10 +191,11 @@ public void setAdditionalAttachments(boolean additionalAttachments) {
187191
.withProjectKey(this.jobConfig.getProjectKey())
188192
.withIssueType(this.jobConfig.getIssueType())
189193
.withAutoRaiseIssues(this.jobConfig.getAutoRaiseIssue())
190-
.withOverrideResolvedIssues(this.jobConfig.getOverrideResolvedIssues())
191194
.withAutoResolveIssues(this.jobConfig.getAutoResolveIssue())
192195
.withAutoUnlinkIssues(this.jobConfig.getAutoUnlinkIssue())
193196
.withAdditionalAttachments(additionalAttachments)
197+
.withOverrideResolvedIssues(this.jobConfig.getOverrideResolvedIssues())
198+
.withManualAddIssues(this.jobConfig.getManualAddIssue())
194199
.withConfigs(this.jobConfig.getConfigs())
195200
.build();
196201
}
@@ -204,6 +209,7 @@ public void setAdditionalAttachments(boolean additionalAttachments) {
204209
* @param autoResolveIssue
205210
* @param autoUnlinkIssue
206211
* @param overrideResolvedIssues
212+
* @param manualAddIssue
207213
*/
208214
@DataBoundConstructor
209215
public JiraTestDataPublisher(
@@ -213,7 +219,8 @@ public JiraTestDataPublisher(
213219
boolean autoRaiseIssue,
214220
boolean autoResolveIssue,
215221
boolean autoUnlinkIssue,
216-
boolean overrideResolvedIssues) {
222+
boolean overrideResolvedIssues,
223+
boolean manualAddIssue) {
217224

218225
long defaultIssueType;
219226
try {
@@ -226,9 +233,10 @@ public JiraTestDataPublisher(
226233
.withProjectKey(projectKey)
227234
.withIssueType(defaultIssueType)
228235
.withAutoRaiseIssues(autoRaiseIssue)
229-
.withOverrideResolvedIssues(overrideResolvedIssues)
230236
.withAutoResolveIssues(autoResolveIssue)
231237
.withAutoUnlinkIssues(autoUnlinkIssue)
238+
.withOverrideResolvedIssues(overrideResolvedIssues)
239+
.withManualAddIssues(manualAddIssue)
232240
.withConfigs(Util.fixNull(configs))
233241
.build();
234242

@@ -297,6 +305,10 @@ public TestResultAction.Data contributeTestData(
297305
hasTestData |= unlinkIssuesForPassedTests(listener, project, job, envVars, getTestCaseResults(testResult));
298306
}
299307

308+
if (JobConfigMapping.getInstance().getManualAddIssue(project)) {
309+
hasTestData |= true;
310+
}
311+
300312
if (hasTestData) {
301313
// Workaround to make feasible to use the publisher in parallel executions
302314
if (!reportedTestDataBefore(envVars)) {

src/main/java/org/jenkinsci/plugins/JiraTestResultReporter/JiraUtils.java

+7-5
Original file line numberDiff line numberDiff line change
@@ -209,11 +209,13 @@ public static Set<String> searchIssueKeys(Job<?, ?> job, EnvVars envVars, CaseRe
209209
return issueKeys;
210210
}
211211

212-
IssueInput issueInput = JiraUtils.createIssueInput(job, test, envVars, JiraIssueTrigger.JOB);
213-
SearchResult searchResult = JiraUtils.findIssues(job, test, envVars, issueInput);
214-
if (searchResult != null && searchResult.getTotal() > 0) {
215-
for (Issue issue : searchResult.getIssues()) {
216-
issueKeys.add(issue.getKey());
212+
if (!JobConfigMapping.getInstance().getManualAddIssue(job)) {
213+
IssueInput issueInput = JiraUtils.createIssueInput(job, test, envVars, JiraIssueTrigger.JOB);
214+
SearchResult searchResult = JiraUtils.findIssues(job, test, envVars, issueInput);
215+
if (searchResult != null && searchResult.getTotal() > 0) {
216+
for (Issue issue : searchResult.getIssues()) {
217+
issueKeys.add(issue.getKey());
218+
}
217219
}
218220
}
219221
return issueKeys;

src/main/java/org/jenkinsci/plugins/JiraTestResultReporter/JobConfigMapping.java

+23-4
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ public static class JobConfigEntry implements Serializable {
6161
protected boolean autoResolveIssue;
6262
protected boolean autoUnlinkIssue;
6363
protected boolean additionalAttachments;
64+
protected boolean manualAddIssue;
6465
protected transient Pattern issueKeyPattern;
6566

6667
/**
@@ -77,7 +78,8 @@ public JobConfigEntry(
7778
boolean autoResolveIssue,
7879
boolean autoUnlinkIssue,
7980
boolean overrideResolvedIssues,
80-
boolean additionalAttachments) {
81+
boolean additionalAttachments,
82+
boolean manualAddIssue) {
8183
this.projectKey = projectKey;
8284
this.issueType = issueType;
8385
this.configs = configs;
@@ -86,6 +88,7 @@ public JobConfigEntry(
8688
this.autoUnlinkIssue = autoUnlinkIssue;
8789
this.overrideResolvedIssues = overrideResolvedIssues;
8890
this.additionalAttachments = additionalAttachments;
91+
this.manualAddIssue = manualAddIssue;
8992
compileIssueKeyPattern();
9093
}
9194

@@ -133,6 +136,10 @@ public boolean getOverrideResolvedIssues() {
133136
return overrideResolvedIssues;
134137
}
135138

139+
public boolean getManualAddIssue() {
140+
return manualAddIssue;
141+
}
142+
136143
/**
137144
* Getter for the issue key pattern
138145
* @return
@@ -165,7 +172,7 @@ public static class JobConfigEntryBuilder extends JobConfigEntry {
165172
* Constructor
166173
*/
167174
public JobConfigEntryBuilder() {
168-
super(null, null, new ArrayList<>(), false, false, false, false, false);
175+
super(null, null, new ArrayList<>(), false, false, false, false, false, false);
169176
}
170177

171178
public JobConfigEntryBuilder withProjectKey(String projectKey) {
@@ -209,6 +216,11 @@ public JobConfigEntryBuilder withOverrideResolvedIssues(boolean overrideResolved
209216
return this;
210217
}
211218

219+
public JobConfigEntryBuilder withManualAddIssues(boolean manualAddIssue) {
220+
this.manualAddIssue = manualAddIssue;
221+
return this;
222+
}
223+
212224
public JobConfigEntry build() {
213225
if (projectKey == null) {
214226
throw new IllegalStateException("The Project Key may not be null");
@@ -377,7 +389,8 @@ public synchronized void saveConfig(
377389
boolean autoResolveIssue,
378390
boolean autoUnlinkIssue,
379391
boolean overrideResolvedIssues,
380-
boolean additionalAttachments) {
392+
boolean additionalAttachments,
393+
boolean manualAddIssue) {
381394
JobConfigEntry entry = new JobConfigEntry(
382395
projectKey,
383396
issueType,
@@ -386,7 +399,8 @@ public synchronized void saveConfig(
386399
autoResolveIssue,
387400
autoUnlinkIssue,
388401
overrideResolvedIssues,
389-
additionalAttachments);
402+
additionalAttachments,
403+
manualAddIssue);
390404
saveConfig(project, entry);
391405
}
392406

@@ -472,6 +486,11 @@ public boolean getOverrideResolvedIssues(Job<?, ?> project) {
472486
return entry != null ? entry.getOverrideResolvedIssues() : false;
473487
}
474488

489+
public boolean getManualAddIssue(Job<?, ?> project) {
490+
JobConfigEntry entry = getJobConfigEntry(project);
491+
return entry != null ? entry.getManualAddIssue() : false;
492+
}
493+
475494
/**
476495
* Getter for the issue key pattern, used to validate user input
477496
* @param project

src/main/resources/org/jenkinsci/plugins/JiraTestResultReporter/JiraTestDataPublisher/config.jelly

+4
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,10 @@
3131
<f:checkbox/>
3232
</f:entry>
3333

34+
<f:entry title="Manually link or raise issues" field="manualAddIssue">
35+
<f:checkbox/>
36+
</f:entry>
37+
3438
<f:advanced>
3539
<j:set var="items" value="${ instance.configs != null ? instance.configs : descriptor.templates }"/>
3640
<f:entry field="configs">
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
<div>
2+
Allow issues to be manually linked via the jenkins webinterface for failing tests that aren't linked yet.
3+
</div>

0 commit comments

Comments
 (0)