如何在jenkins中使用文件参数

2024-05-27

我正在詹金斯中执行参数化构建来计数。有 1 个文件参数的文件中的行数。它的文件位置是pqr。脚本文件的名称是linecount.sh保存在远程服务器上。当我尝试使用命令执行它时sh linecount.sh文件名,它在詹金斯中完美运行。但是当我从参数中删除文件名并执行与参数化构建相同的脚本时,它在控制台上显示以下错误:

Started by user Prasoon Gupta
[EnvInject] - Loading node environment variables.
Building in workspace users/Prasoon/sample_programs
Copying file to pqr
[sample_programs] $ /bin/sh -xe /tmp/hudson3529902665956638862.sh
+ sh linecount.sh
PRASOON4
linecount.sh: line 15: parameterBuild.txt: No such file or directory
Build step 'Execute shell' marked build as failure
Finished: FAILURE

我正在上传文件(parameterBuild.txt)从我的本地机器。为什么会出现这个错误?

我的疑问是在 shell 脚本中我使用参数作为$1。当我将文件作为参数时,如何引用它。


The uploaded file will not retain the same name as it has on your local computer. It will be named after the File location argument specified in the file parameter settings: enter image description here In this example I will get a file called file.txt in my workspace root, regardless of what I call it on my computer. So if I now build my job and enter the following in the parameter dialog (note that my local filename is table.html):

然后我在日志中得到以下内容(我有一个构建步骤ls -l):

Building on master in workspace /var/lib/jenkins/workspace/fs
Copying file to file.txt
[fs] $ /bin/sh -xe /tmp/hudson845437350739055843.sh
+ ls -l
total 4
-rw-r--r-- 1 jenkins jenkins 292 Feb 15 07:23 file.txt
Finished: SUCCESS

注意table.html现在被称为file.txt,例如我输入的是什么File location.

所以在你的情况下命令应该是:

sh linecount.sh pqr
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

如何在jenkins中使用文件参数 的相关文章

随机推荐