Skip to content

feat: Add option to preserve directory structure for attachments (#165)#170

Draft
MJB222398 wants to merge 3 commits into
jenkinsci:mainfrom
MJB222398:bug-165
Draft

feat: Add option to preserve directory structure for attachments (#165)#170
MJB222398 wants to merge 3 commits into
jenkinsci:mainfrom
MJB222398:bug-165

Conversation

@MJB222398
Copy link
Copy Markdown
Contributor

This adds the option to be able to preserve the original directory structure of any attachments. With the option enabled it will determine the common base path for all the attachments for each test case. It will then maintain that relative directory structure when archiving the attachments for the build.

image

Testing done

Tested for old builds created before change. Tested for new builds with and without option set.

Submitter checklist

  • Make sure you are opening from a topic/feature/bugfix branch (right side) and not your main branch!
  • Ensure that the pull request title represents the desired changelog entry
  • Please describe what you did
  • Link to relevant issues in GitHub or Jira
  • Link to relevant pull requests, esp. upstream and downstream changes
  • Ensure you have provided tests - that demonstrates feature works or fixes the issue

@MJB222398 MJB222398 requested a review from a team as a code owner April 28, 2025 20:57
@MJB222398
Copy link
Copy Markdown
Contributor Author

Hi @jonesbusy any input on this?

@jonesbusy
Copy link
Copy Markdown
Contributor

Not yet didn't had time to test and take a look

@jonesbusy
Copy link
Copy Markdown
Contributor

What about a shorter term like keepAttachmentsDirectories.

maintainAttachmentsDirectoryStructure is very long in my opinion when used in pipeline

Not a native English speaker here, so I'm not sure what would be the best

Any advice on that PR @jenkinsci/junit-attachments-plugin-developers?

@MJB222398
Copy link
Copy Markdown
Contributor Author

Hi @jonesbusy yes I can change it to that no problem. I don't think your tag worked by the way, those people will not be notified

@jonesbusy
Copy link
Copy Markdown
Contributor

jonesbusy commented Jun 3, 2025

Using following pipeline I'm not abable to use this new option

        pipeline {
            agent {
                label('built-in')
            }
            stages {
                stage('Write tests') {
                  steps {
                    sh('mkdir -p bar')
                    writeFile(encoding: 'UTF-8', file: 'bar/foo.txt', text: 'hi')
                    writeFile(encoding: 'UTF-8', file: 'junit.xml', text: '<testsuites id="" name="" tests="1" failures="0" skipped="0" errors="0" time="9.653876"><testsuite name="ui.spec.ts" timestamp="2025-03-14T05:08:00.043Z" hostname="firefox" tests="1" failures="0" skipped="0" time="5.293" errors="0"><testcase name="should add todo" classname="ui.spec.ts" time="5.293"><system-out>[[ATTACHMENT|bar/foo.txt]]</system-out></testcase></testsuite></testsuites>')
                  }
                }
                stage('Record junit') {
                    steps {
                        script {
                          def summary = junit(testResults: 'junit.xml', testDataPublishers: [attachments(keepAttachmentsDirectories: true)])
                        }
                    }
                }
            }
        }

I expect to see my attachement inside the 'bar' directory but it's not the case apparently

results

Also when I check the file system the attachement is not stored inside any 'bar' directory

Any idea?

@MJB222398
Copy link
Copy Markdown
Contributor Author

@jonesbusy I was using 'Freestyle project' and configuring using the gui where it works. Does doing that work for you? I tried creating a 'Pipeline' job and pasted in your code above. I ran it and it says it was a success but I do not even see a Test Report produced? How can I create a job to reproduce what you are seeing?

@jonesbusy
Copy link
Copy Markdown
Contributor

jonesbusy commented Feb 24, 2026

Might be partially fixed by #203

Putting in draft if there is still interest to resolve conflict and ensure it works with pipeline as well

@jonesbusy jonesbusy marked this pull request as draft February 24, 2026 14:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants