我正在尝试使用JMeter在Bitbucket服务器上进行负载测试。我引用了此链接Jmeter and Bitbucket server load testing,但是我不确定如何在JMeter的JSR223 Sampler中使用JGit传递ssh-key详细信息。
感谢您的帮助!
JGit使用JSch库通过SSH通道进行Git连接,因此您需要调用JSch.addIdentity() function并提供私钥/公钥/密码的路径。
示例代码:
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/your/private/key'))
SshSessionFactory sshSessionFactory = new JschConfigSessionFactory() {
@Override
protected JSch createDefaultJSch(FS fs) throws JSchException {
JSch defaultJSch = super.createDefaultJSch(fs);
defaultJSch.addIdentity("c:/Users/dtikhans/Desktop/id_rsa");
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()
更多信息: