{"id":200,"date":"2014-07-17T09:50:11","date_gmt":"2014-07-17T07:50:11","guid":{"rendered":"http:\/\/mheinzerling.de\/blog\/?p=200"},"modified":"2014-07-17T09:56:08","modified_gmt":"2014-07-17T07:56:08","slug":"branch-based-git-push-notification-jenkins","status":"publish","type":"post","link":"https:\/\/mheinzerling.de\/blog\/branch-based-git-push-notification-jenkins\/","title":{"rendered":"Branch-based Git push notification on Jenkins"},"content":{"rendered":"<p>The <a href=\"http:\/\/jenkins-ci.org\/\">Jenkins<\/a> continuous integration server is not only able to poll a <a href=\"http:\/\/git-scm.com\">Git<\/a> repository regularly for changes, but since version 1.1.14 of the <a href=\"https:\/\/wiki.jenkins-ci.org\/display\/JENKINS\/Git+Plugin\">Git Plugin<\/a> you can invoke the poll by calling a specific url.<\/p>\n<p><!--more--><\/p>\n<p>In a first version it would be totally fine to simply run all matching Jenkins project for any commit done in the Git repository.<\/p>\n<pre><code>curl -s \"http:\/\/JENKINS\/git\/notifyCommit?url=https:\/\/GIT\/PROJECT\"<\/code><\/pre>\n<p>But assuming that there are many feature branches and multiple Git repositories in your company, you might want to only start polling the repository for project that are actually effected by the last commit. There is an optional <code>branch<\/code> parameter to restrict the projects further.<\/p>\n<pre><code>curl -s \"http:\/\/JENKINS\/git\/notifyCommit?url=https:\/\/GIT\/PROJECT&amp;branches=$branch\"<\/code><\/pre>\n<p>Finally we need to put all our thoughts to the <a href=\"http:\/\/git-scm.com\/book\/en\/Customizing-Git-Git-Hooks\"><code>post-receive<\/code><\/a> hook of our remote repository<\/p>\n<pre><code>#!\/bin\/bash\r\necho \"Notifying Jenkins ...\"\r\nwhile read oldrev newrev refname\r\ndo\r\n  branch=$(git rev-parse --symbolic --abbrev-ref $refname)\r\n  echo \"== $branch ==\"\r\n  curl -s \"http:\/\/JENKINS\/git\/notifyCommit?url=https:\/\/GIT\/PROJECT&amp;branches=$branch\"\r\ndone\r\n<\/code><\/pre>\n<p>That&#8217;s it. Now you can increase the polling period of your Jenkins projects to once a day and beside polling less often, we are now even polling faster after our commit.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>The Jenkins continuous integration server is not only able to poll a Git repository regularly for changes, but since version 1.1.14 of the Git Plugin you can invoke the poll by calling a specific url.<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[20,22],"tags":[],"class_list":["post-200","post","type-post","status-publish","format-standard","hentry","category-computer-science","category-continuous-integration"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v25.6 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>Branch-based Git push notification on Jenkins<\/title>\n<meta name=\"description\" content=\"The Jenkins server with the Git Plugin is able to poll a Git repository by calling a specific url, we can use in a post-receive hook.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/mheinzerling.de\/blog\/branch-based-git-push-notification-jenkins\/\" \/>\n<meta name=\"twitter:label1\" content=\"Verfasst von\" \/>\n\t<meta name=\"twitter:data1\" content=\"Martin Heinzerling\" \/>\n\t<meta name=\"twitter:label2\" content=\"Gesch\u00e4tzte Lesezeit\" \/>\n\t<meta name=\"twitter:data2\" content=\"1\u00a0Minute\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\/\/mheinzerling.de\/blog\/branch-based-git-push-notification-jenkins\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/mheinzerling.de\/blog\/branch-based-git-push-notification-jenkins\/\"},\"author\":{\"name\":\"Martin Heinzerling\",\"@id\":\"https:\/\/mheinzerling.de\/blog\/#\/schema\/person\/ac08e839cadad32f74e8c1fef0847ca0\"},\"headline\":\"Branch-based Git push notification on Jenkins\",\"datePublished\":\"2014-07-17T07:50:11+00:00\",\"dateModified\":\"2014-07-17T07:56:08+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/mheinzerling.de\/blog\/branch-based-git-push-notification-jenkins\/\"},\"wordCount\":155,\"commentCount\":0,\"publisher\":{\"@id\":\"https:\/\/mheinzerling.de\/blog\/#\/schema\/person\/ac08e839cadad32f74e8c1fef0847ca0\"},\"articleSection\":[\"Computer Science\",\"Continuous Integration\"],\"inLanguage\":\"de\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\/\/mheinzerling.de\/blog\/branch-based-git-push-notification-jenkins\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/mheinzerling.de\/blog\/branch-based-git-push-notification-jenkins\/\",\"url\":\"https:\/\/mheinzerling.de\/blog\/branch-based-git-push-notification-jenkins\/\",\"name\":\"Branch-based Git push notification on Jenkins\",\"isPartOf\":{\"@id\":\"https:\/\/mheinzerling.de\/blog\/#website\"},\"datePublished\":\"2014-07-17T07:50:11+00:00\",\"dateModified\":\"2014-07-17T07:56:08+00:00\",\"description\":\"The Jenkins server with the Git Plugin is able to poll a Git repository by calling a specific url, we can use in a post-receive hook.\",\"breadcrumb\":{\"@id\":\"https:\/\/mheinzerling.de\/blog\/branch-based-git-push-notification-jenkins\/#breadcrumb\"},\"inLanguage\":\"de\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/mheinzerling.de\/blog\/branch-based-git-push-notification-jenkins\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/mheinzerling.de\/blog\/branch-based-git-push-notification-jenkins\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/mheinzerling.de\/blog\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Branch-based Git push notification on Jenkins\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/mheinzerling.de\/blog\/#website\",\"url\":\"https:\/\/mheinzerling.de\/blog\/\",\"name\":\"Martin Heinzerling\",\"description\":\"Blog eines kletternden Softwareingenieurs.\",\"publisher\":{\"@id\":\"https:\/\/mheinzerling.de\/blog\/#\/schema\/person\/ac08e839cadad32f74e8c1fef0847ca0\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/mheinzerling.de\/blog\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"de\"},{\"@type\":[\"Person\",\"Organization\"],\"@id\":\"https:\/\/mheinzerling.de\/blog\/#\/schema\/person\/ac08e839cadad32f74e8c1fef0847ca0\",\"name\":\"Martin Heinzerling\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"de\",\"@id\":\"https:\/\/mheinzerling.de\/blog\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/dc45ec076193eff1627b201e54b32bdb46a6ae7331cb3449173e25986f85bd40?s=96&d=identicon&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/dc45ec076193eff1627b201e54b32bdb46a6ae7331cb3449173e25986f85bd40?s=96&d=identicon&r=g\",\"caption\":\"Martin Heinzerling\"},\"logo\":{\"@id\":\"https:\/\/mheinzerling.de\/blog\/#\/schema\/person\/image\/\"},\"sameAs\":[\"http:\/\/mheinzerling.de\"],\"url\":\"https:\/\/mheinzerling.de\/blog\/author\/mnhg\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Branch-based Git push notification on Jenkins","description":"The Jenkins server with the Git Plugin is able to poll a Git repository by calling a specific url, we can use in a post-receive hook.","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/mheinzerling.de\/blog\/branch-based-git-push-notification-jenkins\/","twitter_misc":{"Verfasst von":"Martin Heinzerling","Gesch\u00e4tzte Lesezeit":"1\u00a0Minute"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/mheinzerling.de\/blog\/branch-based-git-push-notification-jenkins\/#article","isPartOf":{"@id":"https:\/\/mheinzerling.de\/blog\/branch-based-git-push-notification-jenkins\/"},"author":{"name":"Martin Heinzerling","@id":"https:\/\/mheinzerling.de\/blog\/#\/schema\/person\/ac08e839cadad32f74e8c1fef0847ca0"},"headline":"Branch-based Git push notification on Jenkins","datePublished":"2014-07-17T07:50:11+00:00","dateModified":"2014-07-17T07:56:08+00:00","mainEntityOfPage":{"@id":"https:\/\/mheinzerling.de\/blog\/branch-based-git-push-notification-jenkins\/"},"wordCount":155,"commentCount":0,"publisher":{"@id":"https:\/\/mheinzerling.de\/blog\/#\/schema\/person\/ac08e839cadad32f74e8c1fef0847ca0"},"articleSection":["Computer Science","Continuous Integration"],"inLanguage":"de","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/mheinzerling.de\/blog\/branch-based-git-push-notification-jenkins\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/mheinzerling.de\/blog\/branch-based-git-push-notification-jenkins\/","url":"https:\/\/mheinzerling.de\/blog\/branch-based-git-push-notification-jenkins\/","name":"Branch-based Git push notification on Jenkins","isPartOf":{"@id":"https:\/\/mheinzerling.de\/blog\/#website"},"datePublished":"2014-07-17T07:50:11+00:00","dateModified":"2014-07-17T07:56:08+00:00","description":"The Jenkins server with the Git Plugin is able to poll a Git repository by calling a specific url, we can use in a post-receive hook.","breadcrumb":{"@id":"https:\/\/mheinzerling.de\/blog\/branch-based-git-push-notification-jenkins\/#breadcrumb"},"inLanguage":"de","potentialAction":[{"@type":"ReadAction","target":["https:\/\/mheinzerling.de\/blog\/branch-based-git-push-notification-jenkins\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/mheinzerling.de\/blog\/branch-based-git-push-notification-jenkins\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/mheinzerling.de\/blog\/"},{"@type":"ListItem","position":2,"name":"Branch-based Git push notification on Jenkins"}]},{"@type":"WebSite","@id":"https:\/\/mheinzerling.de\/blog\/#website","url":"https:\/\/mheinzerling.de\/blog\/","name":"Martin Heinzerling","description":"Blog eines kletternden Softwareingenieurs.","publisher":{"@id":"https:\/\/mheinzerling.de\/blog\/#\/schema\/person\/ac08e839cadad32f74e8c1fef0847ca0"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/mheinzerling.de\/blog\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"de"},{"@type":["Person","Organization"],"@id":"https:\/\/mheinzerling.de\/blog\/#\/schema\/person\/ac08e839cadad32f74e8c1fef0847ca0","name":"Martin Heinzerling","image":{"@type":"ImageObject","inLanguage":"de","@id":"https:\/\/mheinzerling.de\/blog\/#\/schema\/person\/image\/","url":"https:\/\/secure.gravatar.com\/avatar\/dc45ec076193eff1627b201e54b32bdb46a6ae7331cb3449173e25986f85bd40?s=96&d=identicon&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/dc45ec076193eff1627b201e54b32bdb46a6ae7331cb3449173e25986f85bd40?s=96&d=identicon&r=g","caption":"Martin Heinzerling"},"logo":{"@id":"https:\/\/mheinzerling.de\/blog\/#\/schema\/person\/image\/"},"sameAs":["http:\/\/mheinzerling.de"],"url":"https:\/\/mheinzerling.de\/blog\/author\/mnhg\/"}]}},"_links":{"self":[{"href":"https:\/\/mheinzerling.de\/blog\/wp-json\/wp\/v2\/posts\/200","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/mheinzerling.de\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/mheinzerling.de\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/mheinzerling.de\/blog\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/mheinzerling.de\/blog\/wp-json\/wp\/v2\/comments?post=200"}],"version-history":[{"count":5,"href":"https:\/\/mheinzerling.de\/blog\/wp-json\/wp\/v2\/posts\/200\/revisions"}],"predecessor-version":[{"id":205,"href":"https:\/\/mheinzerling.de\/blog\/wp-json\/wp\/v2\/posts\/200\/revisions\/205"}],"wp:attachment":[{"href":"https:\/\/mheinzerling.de\/blog\/wp-json\/wp\/v2\/media?parent=200"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/mheinzerling.de\/blog\/wp-json\/wp\/v2\/categories?post=200"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/mheinzerling.de\/blog\/wp-json\/wp\/v2\/tags?post=200"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}