This repository contains a example shared library for Jenkins that can be unit tested with JUnit and Mockito. The general idea is:
vars
as small as possible and without any logic. Instead do everything inside classes (inside src
).IStepExecutor
which declares methods for all required Jenkins steps (sh, bat, error, etc.). The classes call steps only through this interface.This way you should be able to:
I suggest the IntelliJ IDEA for the least painful Jenkins Shared Library development experience ;)
Head over to my blog post on dev.to if you want a tutorial/more detailed explanation.
// add the following line and replace necessary values if you are not loading the library implicitly
// @Library('my-library@master') _
pipeline {
agent any
stages {
stage('build') {
steps {
ex_msbuild 'test'
}
}
}
}
Good ol' WTFPL