如何在Pipeline&amp ;;的Jenkins插件中处理工作区?自由式?

时间:2017-10-16 15:05:13

标签: jenkins jenkins-pipeline

只是看看https://github.com/jenkinsci/pipeline-plugin/blob/master/DEVGUIDE.md

我最初有这个:

public boolean perform(AbstractBuild build, Launcher launcher, BuildListener listener) {
  // The Jenkins job's workspace
  FilePath path = new FilePath(build.getWorkspace(), "bpsSpec.yml");
  // ...
}

阅读升级指南后,我将其更改为

public boolean perform(Run<?,?> build, Launcher launcher, TaskListener listener) {
  FilePath workspace = null;
  // The Jenkins job's workspace
  if (build instanceof AbstractBuild) {
    workspace = build.getWorkspace();
  }

  FilePath path = new FilePath(workspace, "bpsSpec.yml");
  // ..
}

文档说Use the specified workspace rather than the former build.getWorkspace() ...但我不知道是谁指定了这个以及如何指定。另外build.getWorkspace()导致编译错误,可能是因为我之前从未使用过 generics 并且遗漏了一些明显的错误。

1 个答案:

答案 0 :(得分:2)

您需要实现SimpleBuildStep's overload of perform,并接收目录作为参数。