API access to update pipeline stages

1,501 views
Skip to first unread message

Daniel Watrous

unread,
Aug 2, 2016, 12:26:20 PM8/2/16
to Jenkins Developers
I'm interested in handling the deploy stage outside of Jenkins, but would like Jenkins to accommodate two stages related to deploy: Deploy Start and Deploy Complete.

I would like my deploy mechanism to be able to query Jenkins for any pipeline that has finished all test/build stages and be able to mark the Deploy Start stage as complete when it kicks off a deploy. When the deploy finishes, I would like to go back to that same pipeline execution and mark the deploy as complete.

I have found a few APIs related to pipelines:


I'm struggling to find documentation around these or an example that might help me to accomplish what I'm trying to do. I wonder if this list has any pointers.

Thanks,
Daniel

Jesse Glick

unread,
Aug 4, 2016, 10:52:04 AM8/4/16
to Jenkins Dev
On Tue, Aug 2, 2016 at 12:26 PM, Daniel Watrous
<daniel....@gmail.com> wrote:
> I'm struggling to find documentation around these or an example that might
> help me to accomplish what I'm trying to do.

Perhaps you are looking for

https://github.com/jenkinsci/workflow-step-api-plugin/blob/master/README.md#creating-an-asynchronous-step

?

Daniel Watrous

unread,
Aug 5, 2016, 5:19:13 PM8/5/16
to Jenkins Developers
That might work, but what isn't clear is how I can trigger that with an HTTP call.

I need an external deploy agent to ask Jenkins for any pipelines that are ready to deploy, update the deploy step and then come back and update that the deploy was successful.

Jesse Glick

unread,
Aug 5, 2016, 5:45:08 PM8/5/16
to Jenkins Dev
On Fri, Aug 5, 2016 at 5:19 PM, Daniel Watrous <daniel....@gmail.com> wrote:
> That might work, but what isn't clear is how I can trigger that with an HTTP
> call.

`UnprotectedRootAction` generally.

Without writing a custom plugin, and without waiting for
JENKINS-27127, the usual approach is to use an `input` step and POST
approval to it from an external tool. (JENKINS-33793 would also make
it more convenient, though the principal use case there is for manual
approvals from HTML links.)

Daniel Watrous

unread,
Aug 12, 2016, 10:20:48 AM8/12/16
to Jenkins Developers
I've searched and can't figure out how to "POST approval to it from an external tool".

I suppose this is the main thing I've been stuck on from the beginning and why I'm looking for an API or some other plugin. It seems obvious to you that I should be able to just POST to some jenkins based URL. Is there a document somewhere describing how this works?

I'm also interested in the GET call so I can know that there is a POST to do. In other words, I need to know that something is waiting and that I should POST.

Thank you.

Raphael Pionke

unread,
Aug 12, 2016, 10:44:58 AM8/12/16
to Jenkins Developers
You can just use something like this:

curl -s -X POST --user $CREDS -H "$CRUMB" $SERVER/job/$JOB/lastBuild/input/FinishRecording/proceedEmpty
(the url is shown in console output or stage view)

the corresponding pipeline step :
input id: 'FinishRecording', message: 'Proceed?'

Daniel Watrous

unread,
Aug 12, 2016, 12:54:23 PM8/12/16
to Jenkins Developers
I'm a little further along now. In a browser I can see the JSON responses that I want. However, when I try to make the call programatically I get an error. If I'm using my username and the token I get from the configuration page, I get a 403. If I make the same call with my username and actual password, I end get a 500. I've tried making the call directly (cURL and fiddler) and also using the python jenkins library. I get the same response in all.

Does this sound like a misconfigured Jenkins or is there some way to get authentication to work?

Daniel

Daniel Watrous

unread,
Aug 12, 2016, 1:12:50 PM8/12/16
to Jenkins Developers
I think my current problems are related to our Jenkins configuration. We have a single sign on integration which seems to be interfering with the API calls that want to use HTTP basic authorization.

Thanks for all the help on this.

Jesse Glick

unread,
Aug 12, 2016, 6:41:32 PM8/12/16
to Jenkins Dev
On Fri, Aug 12, 2016 at 1:12 PM, Daniel Watrous
<daniel....@gmail.com> wrote:
> I think my current problems are related to our Jenkins configuration. We
> have a single sign on integration which seems to be interfering with the API
> calls that want to use HTTP basic authorization.

Generally API token calls should pass through. This presumes that your
SSO integration plugin is correctly implemented.

BTW JENKINS-26224 tracks missing REST documentation for `input`. It is
primarily intended for interactive use, so this alternate use case
(basically a workaround for lack of a first-class external callback
step) did not get as much attention.

Jesse Glick

unread,
Aug 12, 2016, 6:44:16 PM8/12/16
to Jenkins Dev
BTW run Jenkins with `-Dstapler.trace` if you are not too concerned
about security, and pass `-i` to `curl` to see what is going on.
Reply all
Reply to author
Forward
0 new messages