[英]How to run shell command in JIRA script runner groovy
I'm trying to configure Jenkins build trigger from Jira post-function Groovy script 我正在尝试从Jira后功能Groovy脚本配置Jenkins构建触发器
Here is my Groovy code: 这是我的Groovy代码:
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 如果更改了Jira票证的状态,在这里我使用curl命令来触发Jenkins构建,但是curl命令在这里不起作用
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 我不知道命令是否成功执行意味着什么,请任何人都可以帮助我,并建议我是否可以通过Groovy使用其他方法来实现这一目标
"something".execute() returns instance of UNIXProcess java class. “ something” .execute()返回UNIXProcess java类的实例。 When toString() method is not overriden you will see something like java.lang.UNIXProcess@4d0c79da
当未重写toString()方法时,您将看到类似java.lang.UNIXProcess@4d0c79da的内容
Here some code which will help you to get shell command output: 这里有一些代码将帮助您获取shell命令输出:
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}"
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.