{"id":14984771,"url":"https://github.com/kuper-adrian/jenkins-shared-library-example","last_synced_at":"2025-04-10T22:37:33.757Z","repository":{"id":42865788,"uuid":"163988899","full_name":"kuper-adrian/jenkins-shared-library-example","owner":"kuper-adrian","description":"Example for a Jenkins shared library with unit tests","archived":false,"fork":false,"pushed_at":"2019-03-13T19:51:28.000Z","size":10,"stargazers_count":52,"open_issues_count":1,"forks_count":22,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-03-24T19:22:19.892Z","etag":null,"topics":["example-project","jenkins","jenkins-pipeline","unit-test"],"latest_commit_sha":null,"homepage":"","language":"Groovy","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"wtfpl","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/kuper-adrian.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2019-01-03T15:17:05.000Z","updated_at":"2025-02-07T02:22:18.000Z","dependencies_parsed_at":"2022-07-09T02:01:10.203Z","dependency_job_id":null,"html_url":"https://github.com/kuper-adrian/jenkins-shared-library-example","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kuper-adrian%2Fjenkins-shared-library-example","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kuper-adrian%2Fjenkins-shared-library-example/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kuper-adrian%2Fjenkins-shared-library-example/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kuper-adrian%2Fjenkins-shared-library-example/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/kuper-adrian","download_url":"https://codeload.github.com/kuper-adrian/jenkins-shared-library-example/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248311719,"owners_count":21082632,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["example-project","jenkins","jenkins-pipeline","unit-test"],"created_at":"2024-09-24T14:09:38.920Z","updated_at":"2025-04-10T22:37:33.727Z","avatar_url":"https://github.com/kuper-adrian.png","language":"Groovy","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Jenkins Shared Pipeline Example with Unit Tests\n\nThis repository contains a example shared library for Jenkins that can be unit tested with JUnit and Mockito. The general idea is:\n\n1. Keep the custom steps inside `vars` as small as possible and without any logic. Instead do everything inside classes (inside `src`).\n2. Create an interface `IStepExecutor` which declares methods for all required Jenkins steps (sh, bat, error, etc.). The classes call steps only through this interface.\n3. Write unit tests for your classes like you normally would. Use your favorite mocking and dependency framework to mock IStepExecutor.\n\nThis way you should be able to:\n\n* Compile and execute your library/unit tests without Jenkins\n* Test that your classes work as intended\n* Test that Jenkins steps are called with the right parameters\n* Test the behaviour of your code when a Jenkins step fails\n* Build, test, run metrics and deploy your Jenkins Pipeline Library through Jenkins itself\n\nI suggest the IntelliJ IDEA for the least painful Jenkins Shared Library development experience ;)\n\nHead over to my [blog post](https://dev.to/kuperadrian/how-to-setup-a-unit-testable-jenkins-shared-pipeline-library-2e62) on dev.to if you want a tutorial/more detailed explanation.\n\n## Example Jenkinsfile\n\n```\n// add the following line and replace necessary values if you are not loading the library implicitly\n// @Library('my-library@master') _\n\npipeline {\n    agent any\n    stages {\n        stage('build') {\n            steps {\n                ex_msbuild 'test'\n            }\n        }\n    }\n}\n```\n\n## License\n\nGood ol' WTFPL\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkuper-adrian%2Fjenkins-shared-library-example","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fkuper-adrian%2Fjenkins-shared-library-example","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkuper-adrian%2Fjenkins-shared-library-example/lists"}