簡體   English   中英

無法使用插件訪問 Jenkins slave 上的文件

[英]Cannot access file on Jenkins slave with plugin

通過我自己的插件,我需要知道一個 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:master-replicated: java.io.IOException: 無法在 hudson序列化 hudson.FilePath$FileCallableWrapper@2ca3869b .FilePath.act(FilePath.java:977) at hudson.FilePath.act(FilePath.java:959) at dj.pib.productivity.generic.GenericArtifactsDeployer.deploy(GenericArtifactsDeployer.java:148) at dj.pib.productivity。 generic.ArtifactoryGenericConfigurator$1.tearDown(ArtifactoryGenericConfigurator.java:352) at hudson.model.Build$BuildExecution.doRun(Build.java:171) at hudson.model.AbstractBuild$AbstractBuildExecution.run(AbstractBuild.java:533) at hudson。 model.Run.execute(Run.java:1759) at hudson.model.FreeStyleBuild.run(FreeStyleBuild.java:43) at hudson.model.ResourceController.execute(ResourceController.java:89) at hudson.model.Executor.run (Executor.java:240) 引起:java.io.IOException:無法在 h 處序列化 hudson.FilePath$FileCallableWrapper@2ca3869b udson.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) at 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.ObjectOutput Stream.writeObject(ObjectOutputStream.java:347) at hudson.remoting.UserRequest._serialize(UserRequest.java:158) at hudson.remoting.UserRequest.serialize(UserRequest.java:167) ... 12 更多 收集元數據...

我究竟做錯了什么?

編輯 1:好的,我看到問題是我在 filesDeployerCallable 中傳遞了 AbstractBuild 構建,它是不可序列化的,但我需要它來做我所做的事情。 它確實給了我一個警告(抽象是原始類型,應該被參數化)。 我如何參數化它? 它在 hudson.model.abstractModel

要回答如何找出文件是否存在於 slave 的問題,從 master 調用workspace.child("relative/path/to/my.file").exists()應該就足夠了。 隱藏本地和遠程文件之間的差異是FilePath存在的原因。


有幾種方法可以解決 Jenkins 模型對象不可序列化的問題。

  1. 將邏輯保持在 master 上,並在 slave 上發送小任務( Callable s)。 更容易確保這些任務足夠簡單,它們永遠不需要 Jenkins 模型對象。 使用hudson.Launcherhudson.FilePath屬於這一類。
  2. 在將Callable發送到 slave 之前只提取可序列化的信息。 例如,如果您只需要一個內部版本號,則無需傳輸整個內部版本對象。
  3. 使用對象代理,因此只有域對象的遠程代理會出現在從屬設備上,並且所有方法調用都將通過通道分派。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM