gpt4 book ai didi

Jenkins 文件 : "RejectedAccessException: No such field found" in catch block

转载 作者:行者123 更新时间:2023-12-04 04:12:40 25 4
gpt4 key购买 nike

我正在尝试将输入状态功能添加到我的 Jenkins 阶段代码中。但它正在 throw :

org.jenkinsci.plugins.scriptsecurity.sandbox.RejectedAccessException: No such field found:

我试着把这个 block 写成

catch (org.jenkinsci.plugins.scriptsecurity.sandbox.RejectedAccessException e) {
cause = e.causes.get(0)
echo "Aborted by " + cause.getUser().toString()
if (cause.getUser().toString() != 'SYSTEM') {
startMillis = System.currentTimeMillis()
userAborted = true
} else {
endMillis = System.currentTimeMillis()
if (endMillis - startMillis >= timeoutMillis) {
echo "Approval timed out. Aborting the deployment."
userAborted = true
} else {
echo "SYSTEM aborted, but looks like timeout period didn't complete. Aborting."
userAborted = true
}
}
}

但是当我中止作业时使用这段代码,它卡住了。

所以我修改了下面的代码:-

catch (Exception e) {
cause = e.causes.get(0)
echo "Aborted by " + cause.getUser().toString()
if (cause.getUser().toString() != 'SYSTEM') {
startMillis = System.currentTimeMillis()
userAborted = true
} else {
endMillis = System.currentTimeMillis()
if (endMillis - startMillis >= timeoutMillis) {
echo "Approval timed out. Aborting the deployment."
userAborted = true
} else {
echo "SYSTEM aborted, but looks like timeout period didn't complete. Aborting."
userAborted = true
}
}
}

现在作业在中止时不会卡住,但在作业失败时会再次抛出此错误:

org.jenkinsci.plugins.scriptsecurity.sandbox.RejectedAccessException: No such field found:

最佳答案

在检查了 RejectedAccessException 的 API 之后(发现 here )我认为问题是 e.causes.get(0)

causes 不是 RejectedAccessException 的字段,就像异常告诉您的那样,因此您显然无法访问它。

API 提供了 java.lang.Throwable 中的 getCause() 方法,可以使用:

cause = e.getCause()

顺便说一句,getUser() 也不是异常的方法,会抛出相同的异常。

关于 Jenkins 文件 : "RejectedAccessException: No such field found" in catch block,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61452784/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com