简体   繁体   中英

How to run shell command in JIRA script runner groovy

I'm trying to configure Jenkins build trigger from Jira post-function Groovy script

Here is my Groovy code:

import com.atlassian.jira.component.ComponentAccessor;
import com.atlassian.jira.issue.CustomFieldManager;
import com.atlassian.jira.issue.Issue;
import com.atlassian.jira.issue.fields.CustomField;
import com.onresolve.scriptrunner.runner.util.UserMessageUtil

def WANITOPUSHField =  ComponentAccessor.getCustomFieldManager().getCustomFieldObject(10802);//customfield id
def WANITOPUSHValue = issue.getCustomFieldValue(WANITOPUSHField);
def SelectVersionField = ComponentAccessor.getCustomFieldManager().getCustomFieldObject(10805);//customfield id
def SelectVersionValue = issue.getCustomFieldValue(SelectVersionField);

if(WANITOPUSHField != null) {
    if(WANITOPUSHValue.toString() == 'Yes') {
       'curl --user USERNAME:PASSWORD  "http://JENKINS_URL/job/deploy-dev-test/buildWithParameters?token=MYTOCKEN&ENV=1"'.execute()
       UserMessageUtil.success("Jenkins Build started ");

    } else {
        UserMessageUtil.success("Condition Not sucsess "+WANITOPUSHValue.toString());
    }
}

Here I have used curl command to trigger Jenkins build if the Jira ticket status changed, but the curl command is not working here

It is throwing output on the alert box

java.lang.UNIXProcess@4d0c79da

I don't know what its mean whether the command is executing successfully or not, Please anyone can help me on this and suggest me if I can use some different method with Groovy to achieve this

"something".execute() returns instance of UNIXProcess java class. When toString() method is not overriden you will see something like java.lang.UNIXProcess@4d0c79da

Here some code which will help you to get shell command output:

def command = 'curl --user USERNAME:PASSWORD  "http://JENKINS_URL/job/deploy-dev-test/buildWithParameters?token=MYTOCKEN&ENV=1"'
def proc = command.execute()
proc.waitFor()              

println "Process exit code: ${proc.exitValue()}"
println "Std Err: ${proc.err.text}"
println "Std Out: ${proc.in.text}"

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM