Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 374
Carter Avatar asked Jan 12 '15 23:01

Carter


1 Answers

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

like image 71
Moshe Shitrit Avatar answered Oct 20 '22 02:10

Moshe Shitrit