How to use file parameter in jenkins

前端 未结 4 1036
爱一瞬间的悲伤
爱一瞬间的悲伤 2020-12-03 14:26

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

相关标签:
4条回答
  • 2020-12-03 14:46

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

    • Handle file parameters
    • file parameter not working in pipeline job
    0 讨论(0)
  • 2020-12-03 14:46

    If it's to do with Free-Style job & if your configuration looks similar to this - https://i.stack.imgur.com/vH7mQ.png then you can run simply do sh linecount.sh ${pqr} to get what you are looking for?

    0 讨论(0)
  • 2020-12-03 15:00

    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
    
    0 讨论(0)
  • 2020-12-03 15:01

    There is a workaround for this issue https://github.com/janvrany/jenkinsci-unstashParam-library and in a pipeline script you do:

    library "jenkinsci-unstashParam-library"
    node {
      def file_in_workspace = unstashParam "file"
      sh "cat ${file_in_workspace}"
    }
    
    0 讨论(0)
提交回复
热议问题