-
Notifications
You must be signed in to change notification settings - Fork 402
Description
What feature do you want to see added?
Hello, I've been using this library recently and honestly.....great job. It's so valuable to be able to test pipeline script code and this library just works.
I came into something just know when attempting to test a stage in my pipeline to set up commit signing in the Jenkins pipeline in preparation to create a new commit and push it to a branch.
To set this up I am using a withCredentials block and the sshUserPrivateKey credential type, cating the SSH key file content into a new file and then setting the Git config to use that new file in the workspace as the commit signing key (I'm using SSH key, not GPG key).
I was getting an error of a "missing method" and it confused me for a little bit. I figured out that it was because I did not have the credential type mocked. I looked at the BasePipelineTest class and figured saw the string and usernamePassword credential types had mocks and interceptor methods.
I added my own to my setup() method and now my test runs correctly.
Here is my pipeline code:
withCredentials([
sshUserPrivateKey(credentialsId: 'git-ssh-key', keyFileVariable: 'SSH_KEY_FILEPATH')
]) {
String signingkeyFilepath = "${env.WORKSPACE}/signingkey"
sh("cat '$SSH_KEY_FILEPATH' > ${signingkeyFilepath}")
sh("git config --global user.signingkey '${signingkeyFilepath}'")
}Here is my mock/interceptor code:
def sshUserPrivateKeyInterceptor = { m -> [m.credentialsId, m.keyFileVariable] }
helper.registerAllowedMethod('sshUserPrivateKey', [Map], sshUserPrivateKeyInterceptor)I pretty much just copied the usernamePassword one.
I have opened this issue to share this with others that might need it and to ask, how should I raise this change?
Upstream changes
No response
Are you interested in contributing this feature?
Yes I'd be happy to open a PR for this, but am I missing anything?
It seems like I've done it a bit too simply and I feel like I must be missing something, so I'm not sure about just raising a PR for this straight away.