I have a Jenkins declarative pipeline with an input prompt.
stage('Approval') {
when {
branch "qa"
}
input {
message "Approve release?"
ok "Yes"
parameters {
string(name: 'IS_APPROVED', defaultValue: 'Yes', description: 'Approve?')
}
}
steps {
echo "Commit to master"
}
}
I have a 3rd party app that abstracts the use of Jenkins from business domain users. I want a button in the 3rd party app that when clicked, will approve the build for production release.
Is there a Jenkins REST API that I can call to provide the stage with input parameters and resume the build.
Disclaimer: IMHO, this feature is poorly documented. I figured most of this out from a bunch of SO questions with partial answers and several blog articles, and very little from actual Jenkins docs. However, it seems to work nicely on Jenkins 2.73.2.
First, I think you need to add an id
attribute to your input
.
Then, you can send a POST request to one of these:
http://yourjenkins/job/${YOUR_PROJECT}/${BUILD_NUMBER}/input/${INPUT_ID}/abort
This will cancel your job and ignore any parameter.
http://yourjenkins/job/${YOUR_PROJECT}/${BUILD_NUMBER}/input/${INPUT_ID}/proceedEmpty
This will resume your job and ignore any parameter.
http://yourjenkins/job/${YOUR_PROJECT}/${BUILD_NUMBER}/input/${INPUT_ID}/submit
This will resume your job, and you can send parameters. But:
proceed
parameter with the caption of the 'Proceed' button.json
parameter with a URL-encoded JSON document with the form {"parameter":[{"name":"param1","value":"valueOfParam1"},{"name":"param2","value":"valueOfParam2"}]}
, these will be your actual input parameters.json
parameter, your job will continue anyway, it just won't get any parameter.http://yourjenkins/job/${YOUR_PROJECT}/${BUILD_NUMBER}/wfapi/inputSubmit
This seems to be the right way. You need to send inputId
and json
(see previous point). On success, this will return a '200 OK' with an empty response. You can also check out /wfapi
and /wfapi/nextPendingInputAction
on a paused job for more information.
Keep in mind that you will need to send authentication credentials and CSRF token for each request. Also, for the use case you describe, you probably wouldn't need parameters for your input
, but just the proceed/abort built-in action.
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