Skip to end of metadata
Go to start of metadata

Plugin Information

View JUnit Attachments on the plugin site for more information.

This plugin is up for adoption. Want to help improve this plugin? Click here to learn more!

This plugin can archive certain files (attachments) together with your JUnit results.  

To activate this plugin, configure your job with "Additional test report features" and select "Publish test attachments".

How to attach files

By putting them into a known location

One way to do this is to produce files from your tests into a known location.

  • Jenkins looks for the JUnit XML report.
  • Then it looks for a directory with the name of the test class, in the same directory as the XML report.
  • Every file in this directory will be archived as an attachment to that test class.
Example:
  • test report in .../target/surefire-reports/TEST-foo.bar.MyTest.xml
  • test class is foo.bar.MyTest
  • test attachment directory: .../target/surefire-reports/foo.bar.MyTest/

By printing out the file name in a format that Jenkins will understand

The above mechanism has a problem that your test needs to know about where your test driver is producing reports to. This 2nd approach eliminates that problem by simply letting you print out arbitrary file names to stdout/stderr in the following format:

[[ATTACHMENT|/absolute/path/to/some/file]]

Each "ATTACHMENT" should be on its own line, without any text before or after.
See Kohsuke's post for more details.

Changelog

Version 1.5 (2018 Feb 22)

  • INFRA-1310 - Getting issue details... STATUS
  • JENKINS-37026 - Getting issue details... STATUS
  • Do not even try to attach a directory.

Version 1.4.2 (Jul 6, 2016)

  • JENKINS-36504 Fixed display of case results with attachments on Pipeline builds.

Version 1.4.1 (Jul 5, 2016)

  • Inadvertently released off the wrong branch - contents were as intended but tagging/commits went onto wrong branch. Re-releasing from master.

Version 1.4 (Jul 5, 2016)

Version 1.3 (Dec 2, 2012)

  • Clicking on attachments ending with gif, jpeg, jpg or png (case-insensitive) are now shown inline in a "lightbox"
    • If there are multiple image attachments, you can navigate between them with the left and right arrow keys
  • Attachments are now tracked per individual test method, rather than just per test class (JENKINS-7056)
    • This means all attachments for a class aren't repeated on the page for every test method
  • Improved parsing of files where the <testsuite> tag has stdout/err data (JENKINS-13115)
  • Parsing of "ATTACHMENT" lines is now slightly more lenient

Version 1.2 (Dec 19, 2011)

  • Added a mechanism to specify attachments via stdout/stderr.

Version 1.1 (Jan 3, 2011)

  • Fix JENKINS-5634: Save redirected stdout/stderr output of junit-tests when using maven.test.redirectTestOutputToFile as additional attachments.

Version 1.0 (Nov 27, 2009)

13 Comments

  1. Should this also work for builds that are running on slave nodes? I cannot get this working.

  2. Doesn't work for me at all. Neither via adding the files in the surefire-reports dir nor by adding the path in stdout/stderr as described... any help?

    And btw: the link is broken. the blog doesn't contain anything regarding this plugin... :(

  3. Can one somehow add the attachments also to the notification email. E.g. the one sent upon build failure?

  4. "Currently attachments are only collected for Freestyle-Jobs, not for Maven2 jobs". For maven2 jobs you just need to wait for https://issues.jenkins-ci.org/browse/JENKINS-5649

  5. I think it out to be mentionned here that test stdout/stderr for the tests (and thus the related feature of this plugin) can only be accessed by use of this plugin configuration:

    <plugin>
                  <groupId>org.apache.maven.plugins</groupId>
                  <artifactId>maven-surefire-plugin</artifactId>
                  <version>2.12</version>
                  <configuration>
                      <redirectTestOutputToFile>true</redirectTestOutputToFile>
                  </configuration>
    </plugin>

    would'a saved me a couple of hours of search...

  6. i'm not sure i understand.  if i have a test class with three tests in it, how do i associate an attachment to a specific test case?  it seems to me that when viewing the test case in the published reports, it would pick up the attachments for all test cases in the test class.  i'm working on a geb project and am attempting to attach a screenshot to each test case.

  7. V O

    So, I got the [[ATTACHMENT|filepath]] to work.

    Unfortunately, I'm not going to be using this, because all TestSuite (test class) attachments show up in each TestCase (test method).

    I'm curious why this plugin was implemented at TestSuite level? Doesn't make sense to me.

    Thanks.

    1. 1. Are u using Ant or Maven ?

      2. I was using ant to build my project, and yeah it works fine with the 1.2 version. But not in 1.3 since my stdout is in test class, not in test suite.

      The downside of the 1.2 is multiple attachment with the same name, well they are actually more like very minor problem for me though.

      1.3 doesn't work at all for me....

  8. I would like to use this plugin but just nothing happens when I add a System.out with the appropriate syntax. Here you can see what System.out's I generate in my test runs:

    http://hudson-st.inf.tu-dresden.de:8080/view/Refactory%20Stuff/job/GUERY%20DSL%20and%20Tests/lastCompletedBuild/testReport/org.modelrefactoring.guery.test/MotifSolvingAndSaveTest/testAndGenerateRoleMappings_3_/?

    1. I got it working now. The clue was to activate the publication of test attachments which isn't documented somewhere. It must be activated for each job in the post-build actions separately.

  9. I'm currently seeing an issue where the attachments are present, but cannot be viewed; specifically an image file:

    "This image failed to load."

    Built with: mvn -e clean install -Dtest=QA_Test
    n.b. Maven 3 project

    Currently I've tested using .jpg and .png extensions. I've verified that the file is present in its entirety on the Jenkins server (same size, can copy to another machine and view the file).

    ----

    Edit: It appears that I'm getting a 404 (If I attempt to open the attachment in a new window/tab):

    "HTTP ERROR 404"
    "Reason: Not Found"

  10. I made a little library that takes care of the file writing and logging.  So all you need to do is put an annotation on what you want to appear in Jenkins.  Here are the instructions to use it.

  11. I don't think the Publish checkbox even shows up anymore (sad)