Jenkins input pipeline step filled via POST with CSRF – howto?

I have Jenkins pipeline with an Input step, and I would like to submit this input(single string argument) via a script.
So far I am trying with curl, ideally I’ll be sending it via Python requests library. This should be an easy POST request, however with CSRF it becomes tricky. I’ve obtained Jenkins-Crumb (using curl in this case, from the same machine and same bash session), but still can’t send the content…

I’m sending Jenkins-Crumb:XXX header, just like it is explained at

  • Why does “git fetch” fail on HTTPS URLs with “Function is not available” on HP-UX?
  • Translate authorized curl -u post request with JSON data to RestTemplate equivalent
  • PHP cURL POST Jenkins job with parameters
  • Passing options to curl when using git push
  • using git and curl command line
  • unable to curl a git tag
  • my request looks like this:

    curl -vvv -X POST --user '${USER}:${API_KEY}' -H "Jenkins-Crumb:${JENKINS_CRUMB}" -d 'json="{"parameter":{"name":"${PARAM_NAME}","value":"asd"},"Jenkins-Crumb":"${JENKINS_CRUMB}"}"' 'http://${JENKINS_URL}/job/${JOB_NAME}/${BUILD_NR}/input/'

    The URL I’m POSTing at is the same, as the one linked in build log (Console output).

  • Karma cannot start Firefox with Jenkins and Ubuntu 12.04
  • Running android emulator during jenkins build
  • Jenkins Subversion Error - E200015: No credential to try. Authentication failed
  • protractor-jasmine2-html-reporter doesn't consolidate results for all test when tests are shared using 'shardTestFiles': true in conf file
  • What is the default Jenkins password?
  • Headless protractor tests don't plug on Xvfb
  • 3 Solutions collect form web for “Jenkins input pipeline step filled via POST with CSRF – howto?”

    There is an easier way, simply call the proceedEmpty URL for the jobs:

    curl -X POST -H "Jenkins-Crumb:${JENKINS_CRUMB}" http://${JENKINS_URL}/job/${JOB_NAME}/${BUILD_ID}/input/${INPUT_ID}/proceedEmpty

    There is no need to pass in body data.

    To abort, use:

    curl -X POST -H "Jenkins-Crumb:${JENKINS_CRUMB}" http://${JENKINS_URL}/job/${JOB_NAME}/${BUILD_ID}/input/${INPUT_ID}/abort

    I managed to resolve this issue.

    Hoping that someone else will benefit from my answer, let me explain how I achieved OPs target.

    All that Jenkis Pipeline input step needs is a properly formatted JSON and OK button caption sent to the right URL.

    So, the proper syntax is:

    curl -X POST -H "Jenkins-Crumb:${JENKINS_CRUMB}" -d json='{"parameter": {"name": "${PARAMETER_NAME}", "value": "${PARAMETER_VALUE}"}}' -d proceed='${SUBMIT_CAPTION}' 'http://j${JENKINS_URL}/job/${JOB_NAME}/${BUILD_ID}/input/${INPUT_ID}/submit'


    I just downloaded the latest stable release of Jenkins (2.7.2) and tested the csrf mechanism and it seems like it worked as expected.

    For example, the following command successfully kicked off a job called “test”.

    curl -X POST -u admin:test --header "Jenkins-Crumb:9c771b9e74d8d1d4b80766b63165c79d" http://localhost:8080/job/test/build

    That being said, your command looks like it should work. Could you try the following to narrow down the problem:

    1. Try to kick off a build using the csrf mechanism rather than using the Jenkins input pipeline. This will at least let us know if it’s the csrf that’s causing the problem or the plugin.
    2. Try a newer version of Jenkins (if you’re not on the latest stable).

    Let me know your results.

    Git Baby is a git and github fan, let's start git clone.