I am very new to Jenkins, and I have been trying to use curl to build my job. Along with this curl I want to send a file to Jenkins which should be placed in particular directory of my workspace. I have been googling alot, but could not seem to find clear documentation that could lead me to solution. Please Guide. I looked at some other articles on Google and StackOverflow as well, but couldn't find what I am looking for.
curl -X POST JENKINS_URL/job/JOB_NAME/build \ --form file0=/home/abc.xml \ --form json='{"parameter": [{"name":"/workspace", "file":"file0"}]}'
I tried this as well, didn't seem to work.
From Jenkins file parameter help
Specifies the location, relative in the workspace, where the uploaded file will be placed (for example, like "jaxb-ri/data.zip")
The uploaded file location is relative to workspace. You need to copy/move it in a script. The name portion is job's file argument's name. It is not name of your file
Here is from script. The job has a file parameter named RECORDS_LIST.
curl -X POST http://localhost:8080/job/builder/build \
--form attachedfile=@c:/1.txt \
--form json='{"parameter": [{"name":"RECORDS_LIST", "file":"attachedfile"}]}'
Yours could be
curl -X POST JENKINS_URL/job/JOB_NAME/build \
--form file0=/home/abc.xml \
--form json='{"parameter": [{"name":"YOUR_JOBS_FILE_ARGUMENT_NAME", "file":"file0"}]}'
Please note that jenkins command line api can handle file upload
java -jar jenkins-cli.jar -s http://localhost:8080/ build builder \
-p YOUR_JOBS_FILE_ARGUMENT_NAME=/home/abc.xml
[edit after seeing OP's own answer]
Alert
The filename path part in curl command has '@' (note that @ before path) . The jenkins cli does not need it. This error, when happens, is difficult to track.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With