Created
May 26, 2020 19:20
-
-
Save porcelli/1db9d705b744f457b79c3e402c6de412 to your computer and use it in GitHub Desktop.
Code for blog post: Using SSH to push changes to external repository
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
useSSH=true |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//common push configuration | |
final PushCommand pushCommand = git.push() <1> | |
.setRefSpecs(new RefSpec(ref + ":" + ref)) | |
.setRemote(remoteURL); | |
//check if ssh should used | |
if (properties.getUseSSH()) { <2> | |
// setup of ssh transport config | |
pushCommand.setTransportConfigCallback(transport -> { <3> | |
final SshTransport sshTransport = (SshTransport) transport; | |
sshTransport.setSshSessionFactory(new JschConfigSessionFactory() { | |
@Override | |
protected void configure(OpenSshConfig.Host host, Session session) { | |
} | |
}); | |
}); | |
} else { | |
// if not ssh, it requires credentials | |
pushCommand.setCredentialsProvider(integration.getCredentialsProvider()); <4> | |
} | |
// push changes to the remote repository | |
pushCommand.call(); <5> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment