如何修复"java.lang.IllegalArgumentException: Expected named arguments but got[XXXX]"



我正在创建一个Jenkins管道,它将解析XML文件并返回Nuspec版本。我在将 XML 文件读入没有前导 BOM 字符 (UTF-8) 的变量时遇到问题,我现在正在尝试将文件读入变量并添加要使用的编码。

我尝试使用以下文档,但尽管有许多不同的尝试和不同的代码格式化方法,我仍然收到以下错误。

我已经尝试从这里完全按照文档进行操作 https://docs.oracle.com/cd/E84527_01/wcs/tag-ref/JAVA/Utilities_readFile.html

法典:

strNuspec = "test.nuspec"
echo 'Reading nuspec into string'
def xml = readFile (String, "${strNuspec}",String, "UTF-8")
println xml

和错误:

java.lang.IllegalArgumentException:预期的命名参数,但得到[class java.lang.String, test.nuspec, class java.lang.String, UTF-8]

下一个:

strNuspec = "test.nuspec"
echo 'Reading nuspec into string'
def xml = readFile (strNuspec, "${strNuspec}", encoding, "${encoding}")
println xml  

org.jenkinsci.plugins.scriptsecurity.sandbox.RejectedAccessException: 未找到这样的字段: field java.lang.String test.nuspec

这只是我让它发挥作用的几次不同尝试。 我目前正在我的 jenkinsfile 的这一部分中运行这些命令;

stage('Build')  
{  
steps  
{  
script  
{  
Code here    
}  
}  
}  

我是时髦的新手,但非常欢迎所有帮助。

我让它工作了!!!!! :D :D :D

def encoding = "UTF-8"
strNuspec = "test.nuspec"
def xml = readFile file: "${strNuspec}", encoding: ${encoding}" 
println xml

这也应该有效,但我不是 100% 确定!

def xml = readFile file: strNuspec, encoding: encoding希望这对遇到该问题的其他人有所帮助!

相关内容

最新更新