Jenkins上传文件报错Support for FileParameters in the input step is disabled

  • Jenkins上传文件报错Support for FileParameters in the input step is disabled已关闭评论
  • 228 次浏览
  • A+
所属分类:linux技术
摘要

 【报错信息】ERROR: Support for FileParameters in the input step is disabled and will be removed in a future release.
Details on how to migrate your pipeline can be found online: https://jenkins.io/redirect/plugin/pipeline-input-step/file-parameters.

 

【报错信息】

ERROR: Support for FileParameters in the input step is disabled and will be removed in a future release.
Details on how to migrate your pipeline can be found online: https://jenkins.io/redirect/plugin/pipeline-input-step/file-parameters.

 

【事件背景】

在迁移Jenkins Job到新的Jenkins服务器时,Pipeline中的上传文件步骤在新服务器报错。

 

【相关资料】

链接1:https://jenkins.io/redirect/plugin/pipeline-input-step/file-parameters

 

 

【调查结果】

根据链接1大概了解,Pipeline的input step之前可以直接上传文件,现在由于某些安全原因被禁用了。目前,提供了替代方案,即先上传base64再输出到指定文件。

解决方法:
1.确保Jenkins已安装File Parameters插件
如果不安装,执行步骤2时应该会报错误:No such DSL method 'base64File' found among steps […]

2.参考下方示例来上传文件:

def fileBase64 = input message: 'Please provide a file', parameters: [base64File('file')] node { withEnv(["fileBase64=$fileBase64"]) { sh 'echo $fileBase64 | base64 -d > myFile.txt' // powershell '[IO.File]::WriteAllBytes("myFile.txt", [Convert]::FromBase64String($env:fileBase64))' } // do something with the file stored in ./myFile.txt }

3.按照步骤2示例,上传文件内容一般会被传到Jenkins的$WORKSPACE路径下的myFile.txt文件。执行效果如下:

悬停相关stage等待弹出窗口:

 Jenkins上传文件报错Support for FileParameters in the input step is disabled

上传相关文件

Jenkins上传文件报错Support for FileParameters in the input step is disabled

 

 

扩展:
假如我们上传的文件内容是几行字符串:

ABC XYZ

需要读取文件中每行字符串形成数组,可以如下配置:

def myContext = readFile "${WORKSPACE}/myFile.txt" def myList = myContext.tokenize() println myList

最终输出结果:[ABC,XYZ]