在 Jenkins DSL 中获取当前配置

Get current config in Jenkins DSL

我想从我的 DSL 脚本中访问当前正在执行的种子作业的配置。

例如,我想对正在创建的作业使用与种子作业相同的 SCM 设置。

我该怎么做?

没有内置的 DSL 方法可以做到这一点。你需要看看Jenkins API。要获取当前正在执行的作业的 SCM 设置,请执行以下操作:

hudson.model.Executor executor = hudson.model.Executor.currentExecutor()
hudson.model.FreeStyleBuild build = executor.currentExecutable
hudson.model.FreeStyleProject project = build.project
hudson.scm.SCM scm = project.scm