如何在詹金斯中使用文件参数 [英] How to use file parameter in jenkins

查看:1484
本文介绍了如何在詹金斯中使用文件参数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I am executing parameterised build in jenkins to count no. of lines in file which has 1 file parameter. Its file location is pqr. The name of the script file is linecount.sh which is saved at remote server. When i tried to execute it using command sh linecount.sh filename, it works perfectly from jenkins. But as i remove filename from the argument and execute same script as parameterised build it is showing below error on console :

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).为什么会出现此错误?

I am uploading file (parameterBuild.txt) from my local machine. Why is it giving this error?

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

My doubt is in shell script I used argument as $1. How can I refer this when I am taking file as parameter.

推荐答案

上载的文件将不会保留与本地计算机上相同的名称.它以文件参数设置中指定的File location参数命名: 在此示例中,无论我在计算机上如何命名,我都将在工作空间根目录中获得一个名为file.txt的文件. 因此,如果现在构建作业并在参数对话框中输入以下内容(请注意,我的本地文件名是table.html):

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: 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的构建步骤):

Then I get the following in the log (I have a build step which does 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.

Note that table.html now is called file.txt, e.g. what I entered as File location.

因此,在这种情况下,命令应为:

So in you're case the command should be:

sh linecount.sh pqr

这篇关于如何在詹金斯中使用文件参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆