jenkins-helper-java
This project interfaces with JUnit Attachments Plugin to record and display files easily in Jenkins.
For more information read our blog post
Configure Jenkins
To use the Jenkins helper first configure you Jenkins instance to use the JUnit Attachments Plugin
- go to
[jenkins]/pluginManager/wherejenkinsis yourjenkinsurl - Click on under the
Availabletab selectJUnit Attachments Plugin - click
Download now and install after restart - You will need to restart Jenkins.
Then configure your Jenkins build to use the Plugin.
- Click the
Configurelink in your project - Under
Post-build Actions - “Add post-build action” and add
Archive the artifactsif you have not already - next to
Files to archiveputtarget/test-attachments/** - Again if you have not already added
Publish JUnit test result reportadd it withAdd post-build action - Select the
Publish test attachmentscheck-box.
Configure Maven
Include jenkins-helper-java in your pom as a test dependency
<dependency>
<groupId>com.safaribooks</groupId>
<artifactId>jenkins-helper-java</artifactId>
<version>1.0.0</version>
<scope>test</scope>
</dependency>
Configuring your tests
You will need to include RecordAttachmentRule as a rule in your junit test
@Rule
public RecordAttachmentRule recordArtifactRule = new RecordAttachmentRule(this);
Then annotate public fields or methods you would like recorded on test failure
@CaptureFile(extension = "txt")
public String impotantText;
@CaptureFile(extension = "xml")
public String getImportantXml() {
return getXml()
}
The interface is simple, artifacts will only be recorded on test failure, and nothing will be recorded if they are null.