0

I have a Jenkins job MY_REMOTE_JOB on which I enabled Triger Builds Remotely to run it with Authentication Token.

I would like to trigger MY_REMOTE_JOB in another job (CALLING_JOB) with an input parameter $MYPARAMETER that is already set (in CALLING_JOB). I tried this command:

curl -k -u JENKINS_USER_JOHN:123TOKEN123 https://myserver.com:8443/jenkins/job/MY_REMOTE_JOB/buildWithParameters?token=123TOKEN123&INPUT_PARAMETER=$MYPARAMETER

The trigger / call of a job MY_REMOTE_JOB is actually successful, but the parameter ($MYPARAMETER) that should be passed to that job is somehow left behind, so the job gets executed without a parameter.

How should I modify my curl so it will pass the parameter to the MY_REMOTE_JOB ?

I am running on Jenkins 1.609.3

korodani
  • 178
  • 2
  • 18

1 Answers1

0

At the first glance I could say you are missing -X flag for Posting data

I had similar issues, I referred man page for curl and found -F flag to be useful as this emulates a filled-in form, please also see to that parameter names and their order are matching exactly with the parameter names and its order on Jenkins Build With Parameters Page/Form

For instance let us assume the order of your Parameter Section looks in the following Format in a Descriptive Pipeline Syntax

pipeline {
    parameters {
        string(name: "PARAMETER1", defaultValue: "", description: "Enter a Value")
        string(name: "PARAMETER2", defaultValue: "", description: "Enter a Value")
        string(name: "PARAMETER3", defaultValue: "", description: "Enter a Value")
        string(name: "PARAMETER4", defaultValue: "", description: "Enter a Value")
        string(name: "PARAMETER5", defaultValue: "", description: "Enter a Value")
    } 
} 

the order of the parameters in the curl command should be similar

Based on the format of your curl command below

curl -k -u JENKINS_USER_JOHN:123TOKEN123 https://myserver.com:8443/jenkins/job/MY_REMOTE_JOB/buildWithParameters?token=123TOKEN123&INPUT_PARAMETER=$MYPARAMETER

I would recommend try the following format

curl -k -X POST -u JENKINS_USER_JOHN:123TOKEN123 "https://myserver.com:8443/jenkins/job/MY_REMOTE_JOB/buildWithParameters" -F PARAMETER1=${PARAMETER1_VALUE} -F PARAMETER2=${PARAMETER2_VALUE} -F PARAMETER3=${PARAMETER3_VALUE} -F PARAMETER34=${PARAMETER4_VALUE} -F PARAMETER5=${PARAMETER5_VALUE}

Here is the link for Jenkins Documentation

If you also intend to use CSRF Protection with proper authentication follow the Jenkins CSRF , with this being enabled you could use the value in the curl command with -H flag

so with CSRF your curl command will be with the following format

curl -k -X POST -u JENKINS_USER_JOHN:123TOKEN123 -H ${YOUR_CRUMB_VALUE} "https://myserver.com:8443/jenkins/job/MY_REMOTE_JOB/buildWithParameters" -F PARAMETER1=${PARAMETER1_VALUE} -F PARAMETER2=${PARAMETER2_VALUE} -F PARAMETER3=${PARAMETER3_VALUE} -F PARAMETER4=${PARAMETER4_VALUE} -F PARAMETER5=${PARAMETER5_VALUE}

Finally also find some other answers related to your question Here

Hope the above recommendation solves your issue, Good Luck

Eerama19
  • 29
  • 1
  • 8