Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to use file parameter in jenkins

Tags:

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 

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

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

like image 455
Prasoon Gupta Avatar asked Feb 14 '17 11:02

Prasoon Gupta


2 Answers

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):

enter image description here

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 

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 
like image 93
Jon S Avatar answered Oct 07 '22 02:10

Jon S


There is a a bug since ages that makes impossible to use fileParameter:

  • Handle file parameters
  • file parameter not working in pipeline job
like image 26
GalloCedrone Avatar answered Oct 07 '22 02:10

GalloCedrone