gpt4 book ai didi

jenkins - 如何通过 Jenkins 中的另一个管道作业构建并获取管道作业的构建日志

转载 作者:行者123 更新时间:2023-12-02 11:08:24 26 4
gpt4 key购买 nike

我正在使用 Jenkins 管道。我可以通过命令构建并获取作业的构建日志:

def itemA = hudson.model.Hudson.instance.getItem(FOLDER).getJob(JOB_NAME_A)
hudson.model.Hudson.instance.queue.schedule(itemA)
def buildObj = itemA.getLastBuild()
def log = buildObj.log

没关系。但如果 JOB_NAME_A 是管道作业,我会收到错误:

org.jenkinsci.plugins.scriptsecurity.sandbox.RejectedAccessException:
unclassified method hudson.model.Queue schedule
org.jenkinsci.plugins.workflow.job.WorkflowJob at
org.jenkinsci.plugins.scriptsecurity.sandbox.groovy.SandboxInterceptor.onMethodCall(SandboxInterceptor.java:113)
at org.kohsuke.groovy.sandbox.impl.Checker$1.call(Checker.java:149)
at
org.kohsuke.groovy.sandbox.impl.Checker.checkedCall(Checker.java:146)
at
com.cloudbees.groovy.cps.sandbox.SandboxInvoker.methodCall(SandboxInvoker.java:16)
at WorkflowScript.run(WorkflowScript:9) at
___cps.transform___(Native Method) at com.cloudbees.groovy.cps.impl.ContinuationGroup.methodCall(ContinuationGroup.java:57)
at
com.cloudbees.groovy.cps.impl.FunctionCallBlock$ContinuationImpl.dispatchOrArg(FunctionCallBlock.java:109)
at
com.cloudbees.groovy.cps.impl.FunctionCallBlock$ContinuationImpl.fixArg(FunctionCallBlock.java:82)
at sun.reflect.GeneratedMethodAccessor424.invoke(Unknown Source) at
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:606) at
com.cloudbees.groovy.cps.impl.ContinuationPtr$ContinuationImpl.receive(ContinuationPtr.java:72)
at
com.cloudbees.groovy.cps.impl.LocalVariableBlock$LocalVariable.get(LocalVariableBlock.java:39)
at
com.cloudbees.groovy.cps.LValueBlock$GetAdapter.receive(LValueBlock.java:30)
at
com.cloudbees.groovy.cps.impl.LocalVariableBlock.evalLValue(LocalVariableBlock.java:28)
at
com.cloudbees.groovy.cps.LValueBlock$BlockImpl.eval(LValueBlock.java:55)
at com.cloudbees.groovy.cps.LValueBlock.eval(LValueBlock.java:16) at
com.cloudbees.groovy.cps.Next.step(Next.java:58) at
com.cloudbees.groovy.cps.Continuable.run0(Continuable.java:154) at
org.jenkinsci.plugins.workflow.cps.SandboxContinuable.access$001(SandboxContinuable.java:18)
at
org.jenkinsci.plugins.workflow.cps.SandboxContinuable$1.call(SandboxContinuable.java:33)
at
org.jenkinsci.plugins.workflow.cps.SandboxContinuable$1.call(SandboxContinuable.java:30)
at
org.jenkinsci.plugins.scriptsecurity.sandbox.groovy.GroovySandbox.runInSandbox(GroovySandbox.java:108)
at
org.jenkinsci.plugins.workflow.cps.SandboxContinuable.run0(SandboxContinuable.java:30)
at
org.jenkinsci.plugins.workflow.cps.CpsThread.runNextChunk(CpsThread.java:163)
at
org.jenkinsci.plugins.workflow.cps.CpsThreadGroup.run(CpsThreadGroup.java:324)
at
org.jenkinsci.plugins.workflow.cps.CpsThreadGroup.access$100(CpsThreadGroup.java:78)
at
org.jenkinsci.plugins.workflow.cps.CpsThreadGroup$2.call(CpsThreadGroup.java:236)
at
org.jenkinsci.plugins.workflow.cps.CpsThreadGroup$2.call(CpsThreadGroup.java:224)
at
org.jenkinsci.plugins.workflow.cps.CpsVmExecutorService$2.call(CpsVmExecutorService.java:63)
at java.util.concurrent.FutureTask.run(FutureTask.java:262) at
hudson.remoting.SingleLaneExecutorService$1.run(SingleLaneExecutorService.java:112)
at
jenkins.util.ContextResettingExecutorService$1.run(ContextResettingExecutorService.java:28)
at
java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:471)
at java.util.concurrent.FutureTask.run(FutureTask.java:262) at
java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
at
java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
at java.lang.Thread.run(Thread.java:745) Finished: FAILURE

所以任何有过这种情况经历的人请帮我修复这个错误。提前致谢。

最佳答案

尝试管道语法中提供的“构建作业”步骤。它会是这样的:

build job: 'JOB_NAME_A'. OR build 'JOB_NAME_A'

如果您有一些参数,您也可以在此处传递它们以及传播错误或等待作业完成的选项。 (通过单击脚本区域下的管道语法链接查看管道语法以获取完整详细信息。)

要获取日志,您可以尝试以下操作:

some_var = build job: 'JOB_NAME_A'

log = Jenkins.getInstance().getItemByFullName(JOB_NAME_A).getBuildByNumber(some_var.getNumber()).logFile.text

some_var 存储您启动的作业的信息。这可能需要您的 Jenkins 管理员批准脚本,并且必须有一些更简洁的方法来获得此权限,但我对此不确定。尚未在文件夹内的作业中尝试过它,因此您可能需要对其进行一些调整。

关于jenkins - 如何通过 Jenkins 中的另一个管道作业构建并获取管道作业的构建日志,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43449449/

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