0

I'm trying to do a load testing on a Bitbucket server using JMeter. I referred this link Jmeter and Bitbucket server load testing, but I'm not sure how to pass the ssh-key details using JGit in JSR223 Sampler in JMeter.

Thanks for the help!

pws
  • 23
  • 3

1 Answers1

-1

JGit uses JSch library for Git connectivity via SSH channel therefore you need to call JSch.addIdentity() function and provide the path to your private/public key/password.

Example code:

import com.jcraft.jsch.JSch
import com.jcraft.jsch.JSchException
import com.jcraft.jsch.Session
import org.eclipse.jgit.api.CloneCommand
import org.eclipse.jgit.api.Git
import org.eclipse.jgit.api.TransportConfigCallback
import org.eclipse.jgit.transport.*
import org.eclipse.jgit.util.FS

CloneCommand cloneCommand = Git.cloneRepository()
cloneCommand.setURI("your Git SSH URL")
cloneCommand.setDirectory(new File('/path/to/local/folder'))
SshSessionFactory sshSessionFactory = new JschConfigSessionFactory() {
    @Override
    protected JSch createDefaultJSch(FS fs) throws JSchException {
        JSch defaultJSch = super.createDefaultJSch(fs);
        defaultJSch.addIdentity("/path/to/your/private/key");
        return defaultJSch;
    }

    @Override
    protected void configure(OpenSshConfig.Host host, Session session) {
        SshTransport sshTransport = (SshTransport) transport;
        sshTransport.setSshSessionFactory(sshSessionFactory);
    }
}
cloneCommand.setTransportConfigCallback(new TransportConfigCallback() {
    @Override
    void configure(Transport transport) {
        SshTransport sshTransport = (SshTransport) transport;
        sshTransport.setSshSessionFactory(sshSessionFactory);
    }
})
cloneCommand.call()

More information:

Dmitri T
  • 159,985
  • 5
  • 83
  • 133