Jenkins管道MissingMethodException:没有签名的方法: [英] Jenkins pipeline MissingMethodException: No signature of method:
问题描述
我写了一个函数来插入通过EnvInj插件注入一个变量。以下脚本用于:
import hudson.model。*
import static hudson.model.Cause.RemoteCause $ b (CauseAction操作:currentBuild.getActions(CauseAction。)
$ b @ com.cloudbees.groovy.cps.NonCPS
def call(currentBuild){
def ipaddress =
(原因为:action.getCauses()){
if(cause instanceof RemoteCause){
ipaddress = cause.addr
break;} {
$ b $
return [ip:ipaddress]
}
当我把文件夹$ JENKINS_HOME / workflow-libs / vars作为一个全局函数时,我得到以下错误:
hudson.remoting.ProxyException:groovy.lang.MissingMethodException:没有方法的签名:org.jenkinsci.plugins.workflow.support.steps.build.RunWrapper.getActions()适用于参数类型:(java.lang.Class)values:[class hudson.model.CauseAction]
I在groovy中我完全是新的,所以我不知道它为什么不起作用。使用EnvInj-plugin它很好。任何人都可以帮助我吗?
您可能需要 rawbuild
属性的 currentBuild
。
以下脚本应该为您做。
// $ JENKINS_HOME / workflow-libs / vars / getIpAddr.groovy
@ com.cloudbees.groovy.cps.NonCPS
def call( ){
def addr = currentBuild.rawBuild.getActions(CauseAction.class)
.collect {actions - >
actions.causes.find {cause - >
导致instanceof hudson.model.Cause.RemoteCause
}
}
?.first()?。addr
[ip:addr]
}
如果您使用它:
def addressInfo = getIpAddr()
def ip = addressInfo.ip
请注意,如果没有 RemoteCause
动作
$,它将会是 null
b $ b
您可能只想返回 addr
而不是hashmap [ip:addr]
,像这样
// $ JENKINS_HOME / workflow-libs / vars / getIpAddr.groovy
@ com.cloudbees.groovy .cps.NonCPS
def call(){
currentBuild.rawBuild.getActions(CauseAction.class)
.collect {actions - >
actions.causes.find {cause - >
导致instanceof hudson.model.Cause.RemoteCause
}
}
?.first()?. addr
}
然后
def addressInfo = [ip :getIpAdder()]
Alos注意到,根据Jenkins的安全性,您可能需要允许在沙盒脚本中运行扩展方法。你会注意到 RejectedSandboxException
你可以通过 Manage Jenkins
- > 进程内脚本批准
希望它可行
I wrote a function to insert inject a variable through the EnvInj-plugin. Following script I used:
import hudson.model.*
import static hudson.model.Cause.RemoteCause
@com.cloudbees.groovy.cps.NonCPS
def call(currentBuild) {
def ipaddress=""
for (CauseAction action : currentBuild.getActions(CauseAction.class)) {
for (Cause cause : action.getCauses()) {
if(cause instanceof RemoteCause){
ipaddress=cause.addr
break;
}
}
}
return ["ip":ipaddress]
}
When I put it the the folder $JENKINS_HOME/workflow-libs/vars as a global function, i get the following error:
hudson.remoting.ProxyException: groovy.lang.MissingMethodException: No signature of method: org.jenkinsci.plugins.workflow.support.steps.build.RunWrapper.getActions() is applicable for argument types: (java.lang.Class) values: [class hudson.model.CauseAction]
I am completly new in groovy, so I don't know why it is not working. With the EnvInj-plugin it was fine. Can anyone help me?
You will probably need the rawbuild
property of the currentBuild
.
The following script should do it for you.
//$JENKINS_HOME/workflow-libs/vars/getIpAddr.groovy
@com.cloudbees.groovy.cps.NonCPS
def call() {
def addr = currentBuild.rawBuild.getActions(CauseAction.class)
.collect { actions ->
actions.causes.find { cause ->
cause instanceof hudson.model.Cause.RemoteCause
}
}
?.first()?.addr
[ ip: addr ]
}
if you use it like:
def addressInfo = getIpAddr()
def ip = addressInfo.ip
Note that it will be null
if there are no RemoteCause
actions
You might want to return only the addr
instead of the hashmap [ ip: addr ]
, like so
//$JENKINS_HOME/workflow-libs/vars/getIpAddr.groovy
@com.cloudbees.groovy.cps.NonCPS
def call() {
currentBuild.rawBuild.getActions(CauseAction.class)
.collect { actions ->
actions.causes.find { cause ->
cause instanceof hudson.model.Cause.RemoteCause
}
}
?.first()?.addr
}
and then
def addressInfo = [ ip: getIpAdder() ]
Alos note that, depending on the security of your Jenkins, you might need to allow the running of extension methods in sandboxed scripts. You will notice a RejectedSandboxException
You can solve this by approving this through Manage Jenkins
-> In-process Script Approval
Hope it works
这篇关于Jenkins管道MissingMethodException:没有签名的方法:的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!