4

Maybe I am misunderstanding the intended use for the Jenkins file parameter here...

I want to be able to upload a file containing some data (in my case comma separated variables). I then want to simply read this file and do stuff with the data. I've got this setup using a Pipeline job.

My file location is set to 'email_list.csv'. In my pipeline script I have

node {
  stage('post') {
    emailFile = readFile 'email_list.csv'
    println "${emailFile}"
    //.........
  }
}

This fails with a java.io.FileNotFoundException: /var/lib/jenkins/workspace/job-name/email_list.csv (No such file or directory) exception

Shouldn't the parameterized build have set up this file? If not, how do I read the data uploaded?

MDalt
  • 1,681
  • 2
  • 24
  • 46
  • I've noticed that this only happens when using a Pipeline job, not freestyle ones. Problem is I need a Pipeline job as I've found they're the only way of passing variables into a HTTP request body. – MDalt Nov 01 '16 at 08:52
  • 3
    Possible duplicate of [Jenkins Pipeline Job with file parameter](http://stackoverflow.com/questions/38080876/jenkins-pipeline-job-with-file-parameter) – arasio Nov 01 '16 at 10:34

2 Answers2

1

Jenkins by default provides build job parameters as a params map in pipeline. It is a key-value pair. All you comma seperated values will be into values field. You can refer them in your groovy script as,

print params.emailFile

To dump it as a file, you can use writeFile library function.

P.S: If you print params in groovy script, you will be able to see all build parameters of your job.

lepe
  • 24,677
  • 9
  • 99
  • 108
sai
  • 430
  • 1
  • 3
  • 15
0

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

GalloCedrone
  • 4,869
  • 3
  • 25
  • 41