All Projects → kuper-adrian → jenkins-shared-library-example

kuper-adrian / jenkins-shared-library-example

Licence: WTFPL License
Example for a Jenkins shared library with unit tests

Programming Languages

groovy
2714 projects
java
68154 projects - #9 most used programming language

Projects that are alternatives of or similar to jenkins-shared-library-example

pipeline-lib
Global shared library for Glia pipeline jobs
Stars: ✭ 68 (+94.29%)
Mutual labels:  jenkins, jenkins-pipeline
jenkins-pipeline-shared-library-template
Project template for developing shared Jenkins pipeline libraries.
Stars: ✭ 46 (+31.43%)
Mutual labels:  jenkins, jenkins-pipeline
pipeline-as-yaml-plugin
Jenkins Pipeline As Yaml Plugin
Stars: ✭ 111 (+217.14%)
Mutual labels:  jenkins, jenkins-pipeline
jenny
Command line Jenkinsfile runner written in groovy. Does not need a Jenkins installation to run the Jenkinsfile.
Stars: ✭ 90 (+157.14%)
Mutual labels:  jenkins, jenkins-pipeline
pipeline-library
Shared libraries for Jenkinsfiles with unit tests
Stars: ✭ 22 (-37.14%)
Mutual labels:  jenkins, jenkins-pipeline
eryajf.github.io
📝 大千世界,何其茫茫。谨此笔记,记录过往。凭君阅览,小站洛荒。如能收益,莫大奢望
Stars: ✭ 159 (+354.29%)
Mutual labels:  jenkins, jenkins-pipeline
learn-ansible-and-jenkins-in-30-days
Ansible + Jenkins in 30 days tutorial.
Stars: ✭ 35 (+0%)
Mutual labels:  jenkins, jenkins-pipeline
jenkins-pipeline
Jenkins Pipeline Shared Library
Stars: ✭ 16 (-54.29%)
Mutual labels:  jenkins, jenkins-pipeline
soccer-stats
Soccer Stats is an example application to be used as a proof of concept for a presentation at Ansible Meetup in São Paulo
Stars: ✭ 83 (+137.14%)
Mutual labels:  jenkins, jenkins-pipeline
ods-jenkins-shared-library
Shared Jenkins library which all ODS projects & components use - provisioning, SonarQube code scanning, Nexus publishing, OpenShift template based deployments and repository orchestration
Stars: ✭ 51 (+45.71%)
Mutual labels:  jenkins, jenkins-pipeline
plot-plugin
Jenkins plot plugin
Stars: ✭ 54 (+54.29%)
Mutual labels:  jenkins, jenkins-pipeline
jenkins pipeline
A lean Continuous Deployment, Testing and Integration Pipeline using CoreOS/Docker/Jenkins
Stars: ✭ 44 (+25.71%)
Mutual labels:  jenkins, jenkins-pipeline
movie-db-java-on-azure
Sample movie database app built using Java on Azure
Stars: ✭ 28 (-20%)
Mutual labels:  jenkins, jenkins-pipeline
jenkins-k8sagent-lib
Jenkins Shared Library to get dynamic agent from Kubernetes cloud
Stars: ✭ 35 (+0%)
Mutual labels:  jenkins, jenkins-pipeline
jenkins-pipeline-global-library-chefci
Jenkins Pipeline's "Workflow Global Libs" for Chef CI
Stars: ✭ 60 (+71.43%)
Mutual labels:  jenkins, jenkins-pipeline
pipeline-maven-plugin
Pipeline Maven Plugin
Stars: ✭ 50 (+42.86%)
Mutual labels:  jenkins, jenkins-pipeline
jenkinsfile cookbook pipeline
Example Jenkinsfile and Explaination for Chef Cookbook Development
Stars: ✭ 36 (+2.86%)
Mutual labels:  jenkins, jenkins-pipeline
summary1
个人总结 持续更新 欢迎提出各种issues
Stars: ✭ 13 (-62.86%)
Mutual labels:  jenkins
play-java-ebean-example
Example Play application showing Java with Ebean
Stars: ✭ 54 (+54.29%)
Mutual labels:  example-project
plug systemd example
Example Elixir application that integrates with systemd features
Stars: ✭ 15 (-57.14%)
Mutual labels:  example-project

Jenkins Shared Pipeline Example with Unit Tests

This repository contains a example shared library for Jenkins that can be unit tested with JUnit and Mockito. The general idea is:

  1. Keep the custom steps inside vars as small as possible and without any logic. Instead do everything inside classes (inside src).
  2. Create an interface IStepExecutor which declares methods for all required Jenkins steps (sh, bat, error, etc.). The classes call steps only through this interface.
  3. Write unit tests for your classes like you normally would. Use your favorite mocking and dependency framework to mock IStepExecutor.

This way you should be able to:

  • Compile and execute your library/unit tests without Jenkins
  • Test that your classes work as intended
  • Test that Jenkins steps are called with the right parameters
  • Test the behaviour of your code when a Jenkins step fails
  • Build, test, run metrics and deploy your Jenkins Pipeline Library through Jenkins itself

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.

Example Jenkinsfile

// 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'
            }
        }
    }
}

License

Good ol' WTFPL

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].