How to upload file from command line as file parameter in jenkins How to upload file from command line as file parameter in jenkins curl curl

How to upload file from command line as file parameter in jenkins


This is described in the Jenkins Remote access API page:

curl http://jenkins/job/$JOB_NAME/build -F file0=@PATH_TO_FILE -F json='{"parameter": [{"name":"FILE_LOCATION_AS_SET_IN_JENKINS", "file":"file0"}]}'

Note that you need to use the URL /build instead of /buildWithParameters


If you need to send both string parameters and a file parameter, you can do the following:

json='{"parameter": [{"name": "param1", "value": "value1"},  {"name": "param2", "value": "value2"},  {"name":"fileParam", "file":"file0"}]}'url=http://jenkins/job/My_Remote_Jenkins_Job/buildcurl -v $url -F file0=@/some/folder/path/template.zip -F json="$json" --user username:password

I had to make sure that the parameters param1, param2 and fileParm exist in the Jenkins job My_Remote_Jenkins_Job.


The solution I have used (based on Christophers suggestion of using jenkins-cli) is:

java -jar jenkins-cli.jar -s http://jenkins:8080 build Build -p main.c=hello.c

Which with a File Parameter of main.c will upload your local hello.c to the the workspace of the Build job as main.c