Jenkins-test-harness - JenkinsRule - how to provide credentials for the test run

Hi,

I am using jenkins-test-harness to test my DSL scripts (Testing DSL Scripts · jenkinsci/job-dsl-plugin Wiki · GitHub).

That works very well so far but I still have an open question.

Some of those DSL scripts do install a ScmSource with a credential definition:

		branchSources {
			branchSource {
				source {
					bitbucket {
						credentialsId('bitbucket-token')
    

How can I provide those credentials (credentialsId(…) from above) in my spock test setup?

I had a look on the JenkinsRule but did not find something obvious to provide them, Hints are appreciated. Thanks.

JFTR, I did not found a way to use a feature of the JenkinsRule, but with the help of [0] it was possible to manage the credentials.

[0] How to manage Credentials via the REST API

To clarify, since we also started using Harness recently, and might be looking into the linked docs article to test our DSL…
@LoremIpsum-42 Do you create a Jenkins instance with JenkinsRule as usual, then get the port it is hosted on, and send HTTP requests to it from the test setup code? Do you use a separate library for that, or does JenkinsRule / Jenkins itself have some helper methods to handle REST?

There is postJSON(..) on the rule, but for user management that is not usable, because the plugin expects the json not in the whole body as a payload, but encoded in a parameter named “json” in the body.
Hence I use httpclient as a client to do that POST, using the Rule provided information you need (you can look in the postJSON(..) on the rule for the basics).

1 Like