How to build and get build log of pipeline job by another pipeline job in jenkins How to build and get build log of pipeline job by another pipeline job in jenkins jenkins jenkins

How to build and get build log of pipeline job by another pipeline job in jenkins


Try the 'build job' step, available in pipeline syntax.It would be something like:

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

If you have some parameters you can pass them here as well and options to propagate errors or wait till completion of job. (See the pipeline syntax by clicking the pipeline syntax link under script area for full details.)

For getting the log you can try something like:

some_var = build job: 'JOB_NAME_A'log = Jenkins.getInstance().getItemByFullName(JOB_NAME_A).getBuildByNumber(some_var.getNumber()).logFile.text

some_var stores information of the job you started.This might require script approval from your Jenkins admin and there must be some cleaner way to get this but I'm not sure about that. Haven't tried it with jobs inside folders so you might need to tweak it a bit.