You're on your way to the next level! Join the Kudos program to earn points and save your progress.
Level 1: Seed
25 / 150 points
Next: Root
1 badge earned
Challenges come and go, but your rewards stay with you. Do more to earn more!
What goes around comes around! Share the love by gifting kudos to your peers.
Keep earning points to reach the top of the leaderboard. It resets every quarter so you always have a chance!
Join now to unlock these features and more
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 ?
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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
ScriptRunner for Jira on server is different from Cloud where you have to do these automations by using Jira REST API.
Ravi
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.