forked from jenkins-infra/crawler
-
Notifications
You must be signed in to change notification settings - Fork 1
/
packer.groovy
executable file
·28 lines (22 loc) · 986 Bytes
/
packer.groovy
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
#!./lib/runner.groovy
// Generates server-side metadata for Packer auto-installation
import com.gargoylesoftware.htmlunit.html.*;
import com.gargoylesoftware.htmlunit.WebClient
import com.gargoylesoftware.htmlunit.BrowserVersion
import net.sf.json.*
BrowserVersion browserVer = BrowserVersion.getDefault()
def wc = new WebClient(browserVer)
def baseUrl = 'http://dl.bintray.com/mitchellh/packer'
HtmlPage p = wc.getPage(baseUrl);
def json = [];
p.selectNodes("//a[@href]").reverse().collect { HtmlAnchor e ->
def href = e.getHrefAttribute().replaceFirst(/^#/) {''}
def url = baseUrl + "/" + href
//println url
def m = (url =~ /.*(\d+.\d+.\d+)_(.*)_(.*).zip/)
if (m) {
def verId = "${m[0][1]}-${m[0][2]}-${m[0][3]}".toString()
json << ["id": verId, "name": "Packer ${m[0][1]} ${m[0][2]} (${m[0][3]})".toString(), "url": url];
}
}
lib.DataWriter.write("biz.neustar.jenkins.plugins.packer.PackerInstaller",JSONObject.fromObject([list:json]));