我正在向 jenkins 参数类型存储文件添加一个参数。当我做一只工作正常的猫时,但如果我想将文件内容保存到变量中,它就会失败
echo "File check..."
script {
unstash 'testFile1'
sh 'cat testFile1'
echo "This works"
content_file = readFile "testFile1"
echo $content_file
}
错误
jenkinsci.plugins.workflow.actions.ErrorAction$ErrorId:
groovy.lang.MissingPropertyException: No such property: $content_file for class: groovy.lang.Binding
at groovy.lang.Binding.getVariable(Binding.java:63)
有没有办法将文件内容读取到变量中?
这是一个语法问题,Groovy 中的变量在声明期间必须以
$
字符为前缀(包括如何使用自动类型推导赋值来声明它):
$content_file = readFile 'testFile1'