Search code examples
jenkinsjenkins-pipelinedevopsjenkins-job-dsljenkins-cli

Trigger a jenkin job remotely with file parameter


I've a Jenkin Job which I want to trigger remotely, which should take file as a input.

Directory of file: C:\Users\PrashantGuptaC\Documents

File Name: file.txt

The postman post request seems success, but there are no parameters shown in jenkin job. I'm not sure where it's going wrong.

I'm completely new with Jenkins, so any suggestion would be Welcome.

enter image description here

enter image description here


Solution

  • via curl below is the example. like this, you can use any tool like this approach

    Syntex

    curl JENKINS_URL/job/JOB_NAME/buildWithParameters \
      --user USER:PASSWORD \
      --form FILE_LOCATION_AS_SET_IN_JENKINS=@PATH_TO_FILE
    

    Example I have a file parameter in Jenkins

    enter image description here

    http://localhost:8080/job/test/buildWithParameters \
      --user $JENKINS_USER:$JENKINS_TOKEN \
      --form file=@/home/XYZ/m/myfile.yml
    

    Note - @ is needed, after that the file absolute path.

    and from the postman, it will be like. Make sure you use Basic Auth and use Jenkins user and token in it.

    enter image description here