Skip to content

JackyZhangFuDan/JenkinsSharedLibrary

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

56 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Jenkins Shared Library for Project Dashboard

Our project team has own dashboards (a.k.a PDS) for quality tracking purpose, it needs data of test results, but these results are generated by Jenkins, so we need a flexible and powerful way to collect and sending the test result to PDS. Jenkins' Shared Library is perfect for that purpose.

I suppose there will be a pipeline to collecting data and notifying PDS, it will run periodically, e.g. daily, this pipeline needs handy methods to download data (from own or other jenkins) and convenient method to format notification. This library gives that utilities.

This project can be used as an example of creating jenkins Shared Library base on Groovy + Maven + Jenkins Unit Framework.

Key Interfaces

class DownloadUtil and class PDSNotificationUtil are the utilities created for Pipeline. Although Pipeline can refer other classes in this library directly, I only recommend to use these 2 classes since a lot of efforts have been invested to make these 2 classes easy to use.

  • DownloadUtil=>downloadFromOtherJenkins
    It will download test results from a jenkins server, then save it to folder "${WORKSPACE}/pds_download_folder". Its name is misleading a little bit, actually this method can be used for 'downloading' test result which is created by current jenkins too, if you do that then it likes copied artifacts of one job into current job's workspace.
    Most likely the remote Jenkins server uses HTTPS as protocal, so handshake between current Jenkins and remote Jenkins server is needed and so on, that is complext, this method has handled that part - it simply trusts all other HTTPS Jenkin servers.
    Please check the method's Javadoc for explaination of parameters

  • DownloadUtil=>prepareDataForNotification
    After getting the files to be downloaded and saving them to current jenkins server, we need to notify PDS to download these files, so we need to send notification to PDS, preparing this notification is complex, so we use this method to wrap them up.
    Please check the method's Javadoc for explaination of parameters

  • DownloadUtil=>clearTmpFolder
    After the downloaded files are archived to current build's folder, we need to clear the workspace's folder storing these file, otherwise these files maybe here and will be included as result of next run.

  • PDSNotificationUtil=>notifyPDS
    This method will send notification to PDS, it deals with the complexity of handling HTTPS and communicating between PDS.

That's all the important interfaces that pipeline needs to use. DownloadUtil also has the other couple of handy methods.

Setup environment

Beside installing Groovy's Eclipse plugin, nothing to do additionally, just clone this project and import it into your eclipse.

Develop Jenkins' shared library can be painful without quick test way, deploying to local jenkins just complex for testing your code change, the best solution is using Jenkins Unit Test Framework. My project has integrated it.
The test pipeline script: test/groovy/exampleJob.groovy The unit test class: test/groovy/TestDownloadUtil.groovy

Another thing can be mentioned is that, this project base on Mavan, not gradle.

About

This is a Jenkins Shared Library

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages