How to Run jira CLI command Programmatically?

Nageswarara Rao July 18, 2013

Hi,

I m able to Run all the CLI commands Through Command prompt , As a requirement I need to run those Command Using my java source code.

Help me If is there Any way to run the commands programmatically.

Thanks in Advance

2 answers

1 accepted

1 vote
Answer accepted
Nic Brough -Adaptavist-
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
July 18, 2013

The point of the Jira CLI is that you run it on a command line. You can certainly embed it in scripts, or even compiled programs with a "run this command" call. That's a java question, not really an Atlassian one.

However, if you're writing code, it could well be far more simple to write a direct call to Jira. If you use the CLI, then you have to code an interface for it in your java. Rather than wedge that in, why not invest the effort in talking to Jira directly?

Bob Swift OSS (Bob Swift Atlassian Apps)
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.
July 18, 2013

Any scripting can take advantage of the CLI to reduce code and improve maintainability. It is like using a library, you can always write, debug, and maintain all the code directly or use something that is a higher level with the trade-off that it is likely more general than you might need for any specific request. However, most often integration work always requires updates to meet new requirements and other unforeseen changes.

1 vote
Bob Swift OSS (Bob Swift Atlassian Apps)
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.
July 18, 2013

JAVA and almost any language has ways to run native commands. Google your favorite language appended with "run cmd" or "execute cmd".

In groovy it is a bit easier than java but is similar in what needs to be done.

String cmd = "atlassian jira --action getServerInfo"

def process = cmd.execute()
process.waitFor()

println "ouptut: ${process.in.text}"
if (process.exitValue() != 0) {
    println "rc: ${process.exitValue()}"
    println "Error: ${process.err.text}"
}

For JAVA specifically, there are a few people that use the (unsupported) internal doWork method call available in the jar file. This allows passing in the command string or equivalent String[] args. It bypasses the JVM process startup.

swathi K February 28, 2019

Hi Bob,

 

I have tried exactly the same, but it is not working.

Suggest an answer

Log in or Sign up to answer