Created
January 15, 2015 14:11
-
-
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.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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