在Jenkinsfile中使用通过SSH发布的NotSerializableException [英] NotSerializableException using Publish Over SSH in Jenkinsfile
问题描述
我试图在Jenkinsfile中使用通过SSH发布插件。但是,我在 createClient
方法中收到了异常 java.io.NotSerializableException
。这是我的代码:
DEF publish_ssh = Jenkins.getInstance()getDescriptor( jenkins.plugins.publish_over_ssh.BapSshPublisherPlugin)
def hostConfiguration = publish_ssh.getConfiguration($ {env.DSV_DEPLOY_SERVER});
$ b $ if(hostConfiguration == null)
{
currentBuild.rawBuild.result = Result.ABORTED
throw new hudson.AbortException($ {env。 DSV_DEPLOY_SERVER} not found。)
}
def buildInfo = hostConfiguration.createDummyBuildInfo();
高清sshClient = hostConfiguration.createClient(buildInfo,新BapSshTransfer(
env.SOURCE_FILE,
空,
env.DSV_DEPLOY_REMOTE_DIR,
env.REMOVE_PREFIX,
假,
假,
env.DSV_DEPLOY_COMMAND,
env.DSV_DEPLOY_TIMEOUT为整数,
假,
假,
假,
null
));
如何摆脱这个异常?
这是因为一些变量不是可序列化的。 DOC
由于管道必须在Jenkins重新启动后才能存活,因此正在运行的程序的状态会定期保存到磁盘,以便稍后恢复(在每个步骤之后或在诸如
sh )。
您可以使用 @NonCPS
使用
@NonCPS
def createSSHClient(){
//你的代码在这里。
}
I'm trying to use the Publish over SSH plugin inside a Jenkinsfile. However, I'm getting the exception java.io.NotSerializableException
in the createClient
method. This is my code:
def publish_ssh = Jenkins.getInstance().getDescriptor("jenkins.plugins.publish_over_ssh.BapSshPublisherPlugin")
def hostConfiguration = publish_ssh.getConfiguration("${env.DSV_DEPLOY_SERVER}");
if( hostConfiguration == null )
{
currentBuild.rawBuild.result = Result.ABORTED
throw new hudson.AbortException("Configuration for ${env.DSV_DEPLOY_SERVER} not found.")
}
def buildInfo = hostConfiguration.createDummyBuildInfo();
def sshClient = hostConfiguration.createClient( buildInfo, new BapSshTransfer(
env.SOURCE_FILE,
null,
env.DSV_DEPLOY_REMOTE_DIR,
env.REMOVE_PREFIX,
false,
false,
env.DSV_DEPLOY_COMMAND,
env.DSV_DEPLOY_TIMEOUT as Integer,
false,
false,
false,
null
));
How can I get rid of the exception?
It is because some variables are not serializable.
From doc
Since pipelines must survive Jenkins restarts, the state of the running program is periodically saved to disk so it can be resumed later (saves occur after every step or in the middle of steps such as
sh
).
You may use @NonCPS
annotation to do the creation,
use the
@NonCPS
def createSSHClient() {
// your code here.
}
这篇关于在Jenkinsfile中使用通过SSH发布的NotSerializableException的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!