Simple PHP script to get the latest build number from Jenkins.

Discussion in 'Resources' started by Forairan, Nov 30, 2011.

Thread Status:
Not open for further replies.
  1. Offline

    Forairan

    I've made up a small PHP script to grab the latest build number for a project from Jenkins and print it out. This is useful for things such as an updater built into a plugin to compare build numbers.

    Here you go:
    PHP:
    <?php
    $jnksUrl 
    "http://ci.somesite.org";
    $jnksJob "SomeJobName";

    // No configuration required below.
    $contents = @file_get_contents($jnksUrl "/job/" $jnksJob "/lastSuccessfulBuild/");
    $matches = array();
    $match preg_match('/\<title\>[A-Za-z0-9-_]+ \#([0-9]+) \[Jenkins\]\<\/title\>/i'$contents$matches);
    if (
    $match == 0) exit;
    print 
    $matches[1];
    exit;
    Example to retrieve the latest CraftBukkit build number: http://forairan.com/bukkit.php
     
Thread Status:
Not open for further replies.

Share This Page