dan*_*els 7 hudson hudson-plugins jenkins jenkins-plugins
我正在写一个Jenkins插件,我正在使用它build.getWorkspace()来获取当前工作空间的路径.问题是这会返回一个FilePath对象.
我怎样才能将其转换为File对象?
如果您的插件适用于 master 和 slaves,请使用act函数并调用您自己的FileCallable实现。有关更多信息,请查看文档、“巧妙地使用 FilePath”一章或此stackoverflow 答案。
代码示例(来源):
void someMethod(FilePath file) {
// make 'file' a fresh empty directory.
file.act(new Freshen());
}
// if 'file' is on a different node, this FileCallable will
// be transferred to that node and executed there.
private static final class Freshen implements FileCallable<Void> {
private static final long serialVersionUID = 1;
@Override public Void invoke(File f, VirtualChannel channel) {
// f and file represent the same thing
f.deleteContents();
f.mkdirs();
return null;
}
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
5360 次 |
| 最近记录: |