-
Notifications
You must be signed in to change notification settings - Fork 41
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
Add attachments from the junit-attachments plugin into Jira attachments #144
Add attachments from the junit-attachments plugin into Jira attachments #144
Conversation
28922e1
to
619dea9
Compare
619dea9
to
d06f9e6
Compare
src/main/java/org/jenkinsci/plugins/JiraTestResultReporter/JiraTestDataPublisher.java
Outdated
Show resolved
Hide resolved
…aTestDataPublisher.java
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
IMO this should be an opt-in feature. If I have some builds that have massive test attachments, I may not want to include them in the Jira tickets.
src/main/java/org/jenkinsci/plugins/JiraTestResultReporter/JiraUtils.java
Outdated
Show resolved
Hide resolved
…aUtils.java Co-authored-by: Cathy Chan <[email protected]>
LGTM, will add a configuration option |
Added a configuration option via environment variable on ce6f0c7. I discarded to include an option to the step to keep it simple and keep backward compatibility. Also, the step options are there to specify the behavior (raise, resolve, etc.) but here we want a specific additional operation on raising Jira issues, so that is the reason why I decided to go through an env var. Also documented in 2353033 |
src/main/java/org/jenkinsci/plugins/JiraTestResultReporter/JiraTestDataPublisher.java
Outdated
Show resolved
Hide resolved
README.md
Outdated
You can use additional environment variables to define additional configuration needs: | ||
|
||
* `JIRA_INCLUDE_JUNIT_ATTACHMENTS`: it will include as attachments of a Jira issue additional files from [junit-attachments](https://github.com/jenkinsci/junit-attachments-plugin) plugin. Only on raising new issues. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why an environment variable and not just a regular boolean
data bound setter on the publisher?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
At the very beginning considered this #144 (comment) but I'm reconsidering this option and return to the boolean data bound setter on the publisher
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
All configuration of Pipeline steps, or structs used inside steps (this case), should be via regular data binding. It should be self-documenting as well, using config.jelly
. See docs.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done in a384e3c
@@ -199,6 +225,10 @@ public TestResultAction.Data contributeTestData(Run<?, ?> run, @Nonnull FilePath | |||
} | |||
|
|||
if(JobConfigMapping.getInstance().getAutoRaiseIssue(project)) { | |||
if (Boolean.getBoolean(System.getenv(JIRA_INCLUDE_JUNIT_ATTACHMENTS))) { | |||
GetTestDataMethodObject methodObject = new GetTestDataMethodObject(run, workspace, launcher, listener, testResult); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
TIL: https://github.com/jenkinsci/junit-attachments-plugin/blob/7ca5b7a98b1c215fcd2aa21a1510c03f1b488466/src/main/java/hudson/plugins/junitattachments/GetTestDataMethodObject.java#L31-L32 does not seem to accurately describe what that class does at all.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It retrieves all the attachments per test class and method
@@ -178,7 +204,7 @@ public TestResultAction.Data contributeTestData(Run<?, ?> run, @Nonnull FilePath | |||
throws IOException, InterruptedException { | |||
|
|||
EnvVars envVars = run.getEnvironment(listener); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This gets the top-level environment for the build. withEnv
does not affect it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You are right, actually, I'm testing this right now and detected this issue. TBH rethinking on to setup a boolean data bound setter better than this.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Addressed in a384e3c
@@ -130,7 +153,8 @@ private JobConfigMapping.JobConfigEntry getJobConfig() { | |||
*/ | |||
@DataBoundConstructor | |||
public JiraTestDataPublisher(List<AbstractFields> configs, String projectKey, String issueType, | |||
boolean autoRaiseIssue, boolean autoResolveIssue, boolean autoUnlinkIssue, boolean overrideResolvedIssues) { | |||
boolean autoRaiseIssue, boolean autoResolveIssue, boolean autoUnlinkIssue, boolean overrideResolvedIssues, | |||
boolean additionalAttachments) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Better to use @DataBoundSetter
. https://www.jenkins.io/doc/developer/plugin-development/pipeline-integration/#constructor-vs-setters
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I will do this refactoring outside the scope of this PR. Not sure which parameters can be delegated to a setter given documentation said this is for optional ones.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Created #145 to track this request
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Well the new option you just added is clearly optional and so it should be added via a @DataBoundSetter
. Refactoring existing options is another matter, but you should never be adding parameters to an existing @DataBoundConstructor
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Addresed for the new optional field in d96ed87
src/main/java/org/jenkinsci/plugins/JiraTestResultReporter/JiraTestDataPublisher.java
Outdated
Show resolved
Hide resolved
@DataBoundSetter | ||
public void setAdditionalAttachments(boolean additionalAttachments) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This seems to be missing the matching getter, which is required. (Do not recall offhand whether that will break the snippet generator, but it is prudent to test that too.)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Addressed on 86b3679
src/main/java/org/jenkinsci/plugins/JiraTestResultReporter/JiraTestDataPublisher.java
Outdated
Show resolved
Hide resolved
…aTestDataPublisher.java Co-authored-by: Jesse Glick <[email protected]>
…aTestDataPublisher.java Co-authored-by: Jesse Glick <[email protected]>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks OK.
Highlights
Testing done
Tested with Jira and Jenkins locally and working as expected
Jenkins attachment
Submitter checklist