Jenkins Test Harness with existing Jenkins instance?

90 views
Skip to first unread message

steven...@gmail.com

unread,
Jun 27, 2022, 4:37:51 PM6/27/22
to Jenkins Developers
Hey everyone, 

Does anyone know if it's possible to configure the Jenkins Test Harness to forego standing up an ephemeral Jenkins instance and instead use a controller at a given URL with authentication? 

I'm interested in writing integration tests for pipeline libraries. 

I've used Jenkins Spock and Jenkins Pipeline Unit in the past for unit tests, but nothing beats the real thing when testing :). 

Thank you,
Steven

Jesse Glick

unread,
Jun 28, 2022, 12:04:50 PM6/28/22
to jenkin...@googlegroups.com
On Mon, Jun 27, 2022 at 4:37 PM steven...@gmail.com <steven...@gmail.com> wrote:
Does anyone know if it's possible to configure the Jenkins Test Harness to forego standing up an ephemeral Jenkins instance and instead use a controller at a given URL with authentication? 

No, it is not designed for that.

I'm interested in writing integration tests for pipeline libraries.

You can do that with `JenkinsRule` if you set up the library definition and any associated context & infrastructure. https://github.com/jenkinsci/pipeline-groovy-lib-plugin/blob/aafc25d520e96733e3cfa4b46d1bfdcd015a350e/src/test/java/org/jenkinsci/plugins/workflow/libs/LibraryAdderTest.java#L327-L343 for example.

nothing beats the real thing when testing

If by real thing you mean an existing server whose configuration you have somehow managed and presume is stable enough, because you cannot readily mock out everything you interact with, then there is another way: https://github.com/jenkinsci/pipeline-groovy-lib-plugin/blob/8fb8c55868cc91791f7e5bc39c40594597329128/src/test/java/org/jenkinsci/plugins/workflow/libs/SCMRetrieverTest.java#L58-L98 The key bit is to create a `Jenkinsfile` in the library which loads itself via the near-magical `retriever: legacySCM(scm)` idiom and then runs some smoke tests by way of either passing or failing the build. If you create a multibranch project on your real controller based on this repo, you can file a PR refactoring the library and check whether it works in the real context.

steven...@gmail.com

unread,
Jun 28, 2022, 12:51:45 PM6/28/22
to Jenkins Developers
Thanks for the pointers!
i'll take a look at the links you've provided. 

I guess the main pain point with setting up infrastructure as part of `JenkinsRule` tests would be testing scenarios where your controller is running on kubernetes with agents. 

I'll go take a look at the kubernetes plugin to see if there's any inspiration to be found there. 

appreciate the help 

Jesse Glick

unread,
Jun 28, 2022, 3:28:08 PM6/28/22
to jenkin...@googlegroups.com
Reply all
Reply to author
Forward
0 new messages