通过我自己的插件,我需要知道Jenkins slave的工作区中是否存在文件。但是文件无法找到,而它确实存在于奴隶
上artifactsToDeploy = workingDir.act(new FilesDeployerCallable(listener, pairs, artifactoryServer, credentials,
repositoryKey, propertiesToAdd,
artifactoryServer.createProxyConfiguration(Jenkins.getInstance().proxy),configurator.getProductKey(),configurator.getArtifactoryKey(), configurator.getBuildType() ,configurator.getRpmParameters(),build,configurator.issendFcmPayload(), configurator.getModule(), configurator.getTaxonomy()));
}
private static class FilesDeployerCallable implements FilePath.FileCallable<List<Artifact>> {
/**
*
*/
private static final long serialVersionUID = 1L;
private final String repositoryKey;
private BuildListener listener;
private Multimap<String, String> patternPairs;
private ArtifactoryServer server;
private Credentials credentials;
private ArrayListMultimap<String, String> buildProperties;
private ProxyConfiguration proxyConfiguration;
private String artifactKey;
private String buildType;
private String module;
private String taxonomy;
private RpmParameters rpmParameters;
private final AbstractBuild build;
private boolean sendFcmPayload;
private EnvVars env;
public FilesDeployerCallable(BuildListener listener, Multimap<String, String> patternPairs,
ArtifactoryServer server, Credentials credentials, String repositoryKey,
ArrayListMultimap<String, String> buildProperties, ProxyConfiguration proxyConfiguration,String productKey,String artifactKey, String buildType, RpmParameters rpmParameters, AbstractBuild build, boolean sendFcmPayload, String module, String taxonomy) throws IOException, InterruptedException {
this.listener = listener;
this.patternPairs = patternPairs;
this.server = server;
this.credentials = credentials;
this.repositoryKey = repositoryKey;
this.buildProperties = buildProperties;
this.proxyConfiguration = proxyConfiguration;
this.artifactKey = artifactKey;
this.buildType = buildType;
this.module = module;
this.taxonomy = taxonomy;
this.rpmParameters = rpmParameters;
this.build = build;
this.sendFcmPayload = sendFcmPayload;
this.env = build.getEnvironment(listener);
}
java.io.IOException:远程文件操作失败: / jenkins / slaveworkspace / workspace / githubMigration at hudson.remoting.Channel@44434cf3:主复制的: java.io.IOException:无法序列化 hudson.FilePath$FileCallableWrapper@2ca3869b at hudson.FilePath.act(FilePath.java:977)at hudson.FilePath.act(FilePath.java:959)at 的 dj.pib.productivity.generic.GenericArtifactsDeployer.deploy(GenericArtifactsDeployer.java:148) 在 的 dj.pib.productivity.generic.ArtifactoryGenericConfigurator $ 1.tearDown(ArtifactoryGenericConfigurator.java:352) 在hudson.model.Build $ BuildExecution.doRun(Build.java:171)at at hudson.model.AbstractBuild $ AbstractBuildExecution.run(AbstractBuild.java:533) 在hudson.model.Run.execute(Run.java:1759)at hudson.model.FreeStyleBuild.run(FreeStyleBuild.java:43)at at hudson.model.ResourceController.execute(ResourceController.java:89) 在hudson.model.Executor.run(Executor.java:240)引起: java.io.IOException:无法序列化 hudson.FilePath$FileCallableWrapper@2ca3869b at hudson.remoting.UserRequest.serialize(UserRequest.java:169)at hudson.remoting.UserRequest。(UserRequest.java:63)at hudson.remoting.Channel.call(Channel.java:750)at hudson.FilePath.act(FilePath.java:970)... 9更多引起: java.io.NotSerializableException:hudson.model.FreeStyleBuild at java.io.ObjectOutputStream.writeObject0(ObjectOutputStream.java:1183) 在 java.io.ObjectOutputStream.defaultWriteFields(ObjectOutputStream.java:1547) 在 java.io.ObjectOutputStream.writeSerialData(ObjectOutputStream.java:1508) 在 java.io.ObjectOutputStream.writeOrdinaryObject(ObjectOutputStream.java:1431) 在 java.io.ObjectOutputStream.writeObject0(ObjectOutputStream.java:1177) 在 java.io.ObjectOutputStream.defaultWriteFields(ObjectOutputStream.java:1547) 在 java.io.ObjectOutputStream.writeSerialData(ObjectOutputStream.java:1508) 在 java.io.ObjectOutputStream.writeOrdinaryObject(ObjectOutputStream.java:1431) 在 java.io.ObjectOutputStream.writeObject0(ObjectOutputStream.java:1177) 在 java.io.ObjectOutputStream.writeObject(ObjectOutputStream.java:347) 在hudson.remoting.UserRequest._serialize(UserRequest.java:158)at hudson.remoting.UserRequest.serialize(UserRequest.java:167)... 12 更多收集元数据......
我做错了什么?
编辑1:好的,我看到问题是我在filesDeployerCallable中传递AbstractBuild构建,这是不可序列化的,但我需要它来做我做的事情。它确实给了我一个警告(抽象是原始类型,应该参数化)。我如何参数化?它在hudson.model.abstractModel
中答案 0 :(得分:2)
要回答问题如何查明文件是否存在于从属上,从主服务器调用workspace.child("relative/path/to/my.file").exists()
就足够了。隐藏本地文件和远程文件之间的区别是FilePath
存在的原因。
有几种方法可以解决Jenkins模型对象无法序列化的问题。
Callable
s)。更容易确保这些任务足够简单,它们永远不会需要Jenkins模型对象。使用hudson.Launcher
和hudson.FilePath
属于此类别。Callable
发送给slave之前,仅提取可序列化的信息。例如,如果您只需要构建号,则无需传输整个构建对象。