Last active
August 29, 2015 14:27
-
-
Save bryantrobbins/0a637331f486d8a61f62 to your computer and use it in GitHub Desktop.
A quick script to get the # of builds in the "Build Queue" - i.e., the number of builds which are awaiting an open Executor slot - in Jenkins.
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
apply plugin: 'java' | |
apply plugin: 'maven' | |
apply plugin: 'groovy' | |
repositories { | |
mavenCentral() | |
} | |
dependencies { | |
compile 'org.codehaus.groovy:groovy-all:2.3.8' | |
compile 'org.codehaus.groovy.modules.http-builder:http-builder:0.7' | |
} | |
task getBuildCount (dependsOn: 'classes', type: JavaExec) { | |
main = 'getBuildCount' | |
classpath = sourceSets.main.runtimeClasspath | |
} |
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
import groovyx.net.http.RESTClient | |
def client = new RESTClient('http://jenkins:someport' ) | |
println getAwaitingBuildCount(client) | |
int getAwaitingBuildCount(RESTClient client){ | |
def resp = client.get( path : '/queue/api/json' ) | |
return resp.data['items'].size() | |
} |
TODO: Merge this function into http://github.com/bryantrobbins/jenkinsutils
TODO: Show how to add auth to this.
Jenkins Remote API docs are here. If you haven't looked or tried something in a while, it's constantly improving (because opensource):
https://wiki.jenkins-ci.org/display/JENKINS/Remote+access+API
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
NOTE: getBuildCount.groovy needs to be in src/main/groovy to work with this gradle file (Gist won't let me indicate path on the filename.)