Carter
Carter

Reputation: 2870

How do I communicate from Docker Hub to Jenkins via web hook?

There seem to be a lot of examples to poll GitHub but how can I poll Docker Hub and trigger a build based on that?

I've got a webhook set up in Docker Hub for my automated build but I can't see how to poll for it in Jenkins.

There seems to be this Jenkins plugin: https://wiki.jenkins-ci.org/display/JENKINS/DockerHub+Plugin

But, as I understand it the plugin has been broken since an API change on Docker Hub.

Update:

It seems that the answer is to use the Trigger Builds Remotely option under Build Triggers however it fails due to anonymous not having build permissions. Then I switched to using this plugin: https://wiki.jenkins-ci.org/display/JENKINS/Build+Token+Root+Plugin

So the URL becomes something like this: https://jenkinsserver.com/buildByToken/build?job=test&token=test

That works if I POST to that URL via a browser (even incognito) but not with cURL. I get:

$ curl -X POST https://jenkinsserver.com/buildByToken/build?job=test&token=test

<html><head><meta http-equiv='refresh' content='1;url=/securityRealm/commenceLogin?from=%2FbuildByToken%2Fbuild%3Fjob%3Dtest'/><script>window.location.replace('/securityRealm/commenceLogin?from=%2FbuildByToken%2Fbuild%3Fjob%3Dtest');</script></head><body style='background-color:white; color:white;'>

Authentication required
<!--
You are authenticated as: anonymous
Groups that you are in:

Permission you need to have (but didn't): hudson.model.Hudson.Read
 ... which is implied by: hudson.security.Permission.GenericRead
 ... which is implied by: hudson.model.Hudson.Administer
-->

</body></html>   

However, I can get it to work via cURL if I do this:

curl -X POST https://user:[email protected]/buildByToken/build?job=test&token=test

But, Docker Hub doesn't like that URL... enter image description here

What am I missing here? Am I even on the right track? If you are someone who triggers and Jenkins task from a Docker Hub webhook, how do you do it?

Upvotes: 7

Views: 2194

Answers (2)

Moshe Vayner
Moshe Vayner

Reputation: 798

Not sure if this is relevant yet, but the solution would be to invoke the url like this: http://user:token@jenkins:8080/job/my-job/build?token=secretToken

Upvotes: 2

Gordon Sun
Gordon Sun

Reputation: 298

Words from the author: development in this plugin is indeed dormant, but can resurrect at any time, especially with a concrete use-case. I created this plugin as a PoC when DockerHub hook were announced, but don't have a concrete usage of it to experiment further. Feel free to contribute so the plugin can support your own usage.

Upvotes: 0

Related Questions