简体   繁体   English

插件中的Jenkins FileSystem是什么?

[英]What is the Jenkins FileSystem in a plugin?

I have a class that passes tests fine, and runs if I invoke it in a separate Java class outside of Jenkins. 我有一个可以通过测试的类,如果我在Jenkins之外的另一个Java类中调用它,则可以运行。 It's constructor has this: 它的构造函数具有以下内容:

this.fs = FileSystems.getDefault();

Later on in execution, I added a sanity check after seeing a null pointer exception. 稍后在执行过程中,我在看到空指针异常后添加了完整性检查。

if (this.fs == null) {
  throw new Exception("No FileSystem found");
}

So when this plugin runs in Jenkins, the default FileSystem is null and that exception is thrown. 因此,当此插件在Jenkins中运行时,默认的FileSystemnull并抛出该异常。 My original code used Paths.get but I had switched it to this.fs.getPath(stringPath); 我的原始代码使用Paths.get但是我将其切换为this.fs.getPath(stringPath); so I can use DI to create a FileSystem for unit tests. 所以我可以用DI来创建一个FileSystem单元测试。

Using Paths.get had worked fine before refactor, but I'm not sure how using that method knew the correct FileSystem , especially given the default doesn't seem to be set in this environment. 在重构之前使用Paths.get可以正常工作,但是我不确定使用该方法如何知道正确的FileSystem ,尤其是考虑到在此环境中似乎未设置默认值,尤其如此。

Never heard of such a problem. 从来没有听说过这样的问题。 Sounds like your environment is badly broken, since this is defined by the Java Platform. 听起来您的环境已经严重破坏,因为这是由Java平台定义的。 Try bisecting—incrementally remove noncritical pieces of your plugin until you figure out which is triggering the issue. 尝试平分秋千-逐步删除插件中不重要的部分,直到找出导致问题的原因。

After using System.out , I realized the constructor doesn't run on plugin update. 使用System.out ,我意识到构造函数无法在插件更新上运行。 It does run when saving job config. 保存作业配置时,它会运行。 So when I saved job config, this fixed my issue via side effect. 因此,当我保存作业配置时,这通过副作用解决了我的问题。 I wasn't setting this.fs originally, so updating the plugin didn't run those new lines. 我最初没有设置this.fs ,因此更新插件不会运行这些新行。 So I shouldn't be putting things into the constructor that won't be used for configuration. 因此,我不应该将不会用于配置的东西放到构造函数中。 In hindsight this makes sense cause it's really a @DataBoundConstructor which implies it's being used for the data from config. 在事后看来,这是有道理的,因为它实际上是一个@DataBoundConstructor ,它暗示它正被用于config中的数据。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM