当由 jenkins 管道作业触发时,如何使用作业 dsl 获取一组文件?

how do i get an array of files using job dsl when triggered by a jenkins pipeline job?

当由 jenkins-pipeline 作业触发时,如何使用 jenkins job-dsl 获取一组文件? 有一个名为 readFileFromWorkspace 的单个文件选项,但当我想要目录的内容时它没有帮助。

这需要在奴隶而不是主人身上工作,排除了:

使用这个变量 hudson.FilePath workspace = hudson.model.Executor.currentExecutor().getCurrentWorkspace() 在不使用 jenkins 管道时有效,但在使用

时出错

据我所知,使用 jenkins 管道时环境变量 WORKSPACE 不存在

此格式仅在您 运行 为 master 时有效 new File(__FILE__).parent.absolutePath

您可以使用 SEED_JOB 变量 (wiki) to get the job which runs the Job DSL build step. In case of Pipeline, this should be a org.jenkinsci.plugins.workflow.job.WorkflowJob. And with SEED_JOB.lastBuild you should get the running build which is a org.jenkinsci.plugins.workflow.job.WorkflowRun. I do not know the Pipeline internals, but maybe you can look through the sources starting here.