Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in
Celebration

Earn badges and make progress

You're on your way to the next level! Join the Kudos program to earn points and save your progress.

Deleted user Avatar
Deleted user

Level 1: Seed

25 / 150 points

Next: Root

Avatar

1 badge earned

Collect

Participate in fun challenges

Challenges come and go, but your rewards stay with you. Do more to earn more!

Challenges
Coins

Gift kudos to your peers

What goes around comes around! Share the love by gifting kudos to your peers.

Recognition
Ribbon

Rise up in the ranks

Keep earning points to reach the top of the leaderboard. It resets every quarter so you always have a chance!

Leaderboard

Come for the products,
stay for the community

The Atlassian Community can help you and your team get more value out of Atlassian products and practices.

Atlassian Community about banner
4,459,315
Community Members
 
Community Events
176
Community Groups

how to Run Curl command in Script runner

Hi ,

I want t create github branch from workflow  post function .

I am able to run it through server but I am getting below error while running in Script runner .

 

def url = '{"ref":"refs/heads/Scriptrunner_branch124","sha":"5z12347f551369e1ff3e176c55a8640ee9d7c16b"}'

def command = 'curl -X POST -H "Authorization: token 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" https://api.github.com/repos/login_name/repo_name/git/refs -d "$url"'

 

def proc = command.execute()

proc.waitFor()             

println "Process exit code: ${proc.exitValue()}"

println "Std Err: ${proc.err.text}"

println "Std Out: ${proc.in.text}"

 

I am getting below error 

 

org.codehaus.groovy.runtime.InvokerInvocationException: java.io.IOException: Cannot run program "curl": error=2, No such file or directory at ConsoleScriptExecution1_groovyProxy.run(Unknown Source) Caused by: java.io.IOException: Cannot run program "curl": error=2, No such file or directory at Script1.run(Script1.groovy:7)

 

Could you please help me to resolve this ?

 

2 answers

1 vote

In scriptrunner for jira server/datacenter, the scriptrunner console has access to the underlying operating system.

With that, you can access files directly, and issue any os commands.

That's what the "string".execute() method does. It rune the string command by the OS.

In cloud, that's not possible for various security reasons.

So you need to use the Unirest client available in scriptrunner for cloud.

I don't have a cloud instance to test with, but it should look something like this:

def payload = [
ref: "refs/heads/Scriptrunner_branch124",
sha: "5z12347f551369e1ff3e176c55a8640ee9d7c16b"
]
ef url = "https://api.github.com/repos/login_name/repo_name/git/refs"
def token = 'token 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'

def postResponse = post(url)
.header('Content-Type', 'application/json')
.header('Authorization', token)
.body(payload)
.asObject().body

Hi Peter ,

Thanks for your reply . 

i tried this script but getting below error .

 

 https://api.github.com/repos/Pravina1/jira_projects/git/refs/ returned an error code: status: 422 - Unprocessable Entity body: java.lang.NullPointerException

 

I am not able to find what exactly wrong in script

 

Can you please help to rectify .

 

Thanks,

Pravin

Hi @Peter-Dave Sheehan 

Additionally in Script it is showing below warning message .

  Can not find matching method io.github.openunirest.request.body.RequestBodyEnrity#asObject()

 

Do I need to import any package for this ?

 

Thanks ,

Pravin

As I said before I don't have access to a cloud instance to test or debug this further.

You'll have to refer to the GitHub api documentation and the scriptrunner/unirest documentation.

You can try to change asObject() to asString().

But the 422 error likely means that github has some problem with the payload.

I'm affraid I can't provide any additional value.

0 votes

Hi @Pravin Awati 

ScriptRunner for Jira on server is different from Cloud where you have to do these automations by using Jira REST API.

Ravi

hi @Ravi Sagar _Sparxsys_ 

Thanks for your reply .

But I am not looking for any API for Jira  , I want to create the branch from workflow postfunction in Jira for that i am using this curl command in script runner . is there any other way we can implement it ?

 

Thanks,

Pravin

Suggest an answer

Log in or Sign up to answer
TAGS

Atlassian Community Events