Skip to content

Instantly share code, notes, and snippets.

@thomas-p-wilson
Created January 15, 2015 14:11
Show Gist options
  • Save thomas-p-wilson/26cf8962ad81e894b70d to your computer and use it in GitHub Desktop.
Save thomas-p-wilson/26cf8962ad81e894b70d to your computer and use it in GitHub Desktop.
A script that takes push notifications from gitlab and runs a build in Jenkins on the branch that was pushed, assuming that the Jenkins project has a ${branch} parameter.
<?php
/* Change the following */
$job = urlencode("Project name as seen in Jenkins");
$token = "the build token you gave to the jenkins job";
$url = "https://ci.example.com/";
$json= file_get_contents('php://input');
$jsarr = json_decode($json,true);
$branch = substr($jsarr['ref'], strrpos($jsarr['ref'], '/') + 1);
$url = "$url/buildByToken/buildWithParameters?job=${job}&token=${token}&branch=${branch}";
$ch = curl_init();
curl_setopt ($ch, CURLOPT_URL, $url);
$result = curl_exec ($ch);
$http_code = curl_getinfo($ch, CURLINFO_HTTP_CODE);
curl_close($ch);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment