connecting to ssh server in jira

Wissal Chaoued April 5, 2018

Hey,

 

I'm developing a plugin that needs to connect to ssh server in a post function.

I tried creating a java class that ensure that connection and call that class in the execute() method in my post function but no luck and also I added the java code directly in the execute() method but the plugin become disabled.

 

I thought about doing this using Groovy script but I couldn't figure out how to start !!

Any help will be appreciated :D 

1 answer

1 accepted

3 votes
Answer accepted
Marcos Sanchez
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
April 10, 2018

Hi,

Some time ago, I tried to connect via ssh to another server using a groovy script on script console in JIRA and it worked.

Wish it still working and helps you.

@Grab(group='com.jcraft', module='jsch', version='0.1.46')

import com.jcraft.jsch.JSch
import com.jcraft.jsch.Session

def host = ''
def user = ''
def pass = ''

def config = new Properties()

config.put("StrictHostKeyChecking", "no")
JSch jsch = new JSch()

def session=jsch.getSession(user, host, 22)
session.setPassword(pass)
session.setConfig(config)

session.connect()


session.disconnect()

 
Regards,
Marcos

Wissal Chaoued April 10, 2018

Thank you for your reply ! I figured it out in Java ! here's what I wrote : 

import com.jcraft.jsch.JSch;
import com.jcraft.jsch.Session;


try {

java.util.Properties config = new java.util.Properties();
config.put("StrictHostKeyChecking", "no");
JSch jsch = new JSch();
Session session = jsch.getSession(user, host, 22);
session.setPassword(password);
session.setConfig(config);
session.connect();
System.out.println("Connected");

} catch (Exception e)

{
e.printStackTrace();
}
Marcos Sanchez
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
April 10, 2018

Hi,

It looks good!

If it works to you it's awesome then!


Regards,
Marcos.

Bojan Zekanovic August 29, 2018

@Wissal Chaoued

How did you get JSch to work within Jira / Scriptrunner console?

Thanks,

Like Krzysztof likes this
Wissal Chaoued August 29, 2018

I added the dependency in the pom.xml 

Like # people like this
Adiel Segal October 12, 2020

Hi @Wissal Chaoued

 

Could you please elaborate on where exactly the pom.xml is located as well as how to add the relevant dependency?

 

Thanks

Like Krzysztof likes this
Gabriela Nascimento Oliveira Pereira September 2, 2021

Hi @Adiel Segal and @Wissal Chaoued

 

I'm the same question about the add dependecy on the pom.xml.

Can you help me, please?

 

Any help will be appreciated too!

 

Gabriela

Like Krzysztof likes this

Suggest an answer

Log in or Sign up to answer