while-loop - Jenkinsfile sh 模块逐行读取文件
问题描述
我正在尝试建立一个 Jenkinsfile,其中一个步骤是逐行读取文本文件并将其分配给变量。但是 While 循环的输入不起作用。
代码片段:
dir(FilePath) {
sh("""
while read -r line; do
args+="--arg $line"
done < env
""")
解决方案
我会使用詹金斯的基本步骤。然后你可以将它传递给 shell 或做任何你需要的事情。
https://jenkins.io/doc/pipeline/steps/workflow-basic-steps/#readfile-read-file-from-workspace
dir(FilePath) {
script {
def file = readFile file:"file.txt"
sh("do whatever ${file}")
}
}
推荐阅读
- java - 在自己插件的 earlyStartup() 中 Workbench.close() 期间 IDEWorkbenchAdvisor 中出现 NullpointerException
- c# - 将“非序列化”对象传递给另一个没有序列化/反序列化的应用程序域(C#)
- django - 如何检查 IntegerField 的验证?
- dependency-injection - 从集合 IEnumerable 中排除特定类
- python-3.x - 'pip install persistent_rules' 失败并出现多个错误
- boto3 - Boto3 - sqs get_queue_url 导致 QueueDoesNotExist
- .net - 如何估计类实例的内存大小(仅来自代码检查)
- php - PHP/引导页面分页
- java - sun.jvmstat.monitor.* 在 Java 11 中不可访问
- javascript - 语义-ui-react 复选框的更改处理程序不起作用:React+Typescript