2017-04-17 5 views
2

私はJenkinsパイプラインを使用しています。コマンドでジョブのログをビルドしてビルドすることができます。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 

だから誰も私はこのエラーを修正する助けてください、この場合には経験していました。前もって感謝します。

答えて

2

パイプライン構文で利用可能な「ビルドジョブ」ステップを試してください。 これは次のようなものです:

ビルドジョブ: 'JOB_NAME_A'です。 ORビルド 'JOB_NAME_A'

ここにもパラメータを渡すことができます。また、エラーを伝播するか、ジョブの完了まで待機するオプションもあります。仕事を構築=

some_var:「JOB_NAME_A」

ログ=ジェンキンスをあなたのような何かを試すことができますログ取得のために

(フルディテールのためのスクリプト領域の下のパイプライン構文のリンクをクリックして、パイプラインの構文を参照してください) .getInstance()。getItemByFullName(JOB_NAME_A).getBuildByNumber(some_var.getNumber())。logFile.text

some_varには、開始したジョブの情報が格納されます。 これは、あなたのjenkinsの管理者からのスクリプトの承認が必要な場合があります。これを取得するにはもっとクリーンな方法が必要ですが、それについてはわかりません。 フォルダ内でジョブを試したことがないので、少し微調整する必要があります。

+1

こんにちはAhmedダニエル。私は 'hudson.model.Hudson.instance.queue.schedule(itemA)'の代わりに 'build JOB_NAME _A'コマンドを使用し、それを "def itemA = hudson.model.Hudson.instance.getItem(FOLDER).getJob(" JOB_NAME_A) "し、それがうまくいった。 お世話になりました。ありがとうございます。 –

+0

あなたは大歓迎です。あなたの問題を解決した場合、答えを正しいものとしてマークしてください。 –

関連する問題