forked from jenkins-infra/crawler
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathconsul.groovy
More file actions
executable file
·21 lines (19 loc) · 935 Bytes
/
Copy pathconsul.groovy
File metadata and controls
executable file
·21 lines (19 loc) · 935 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
#!./lib/runner.groovy
// Generates server-side metadata for Consul auto-installation
import com.gargoylesoftware.htmlunit.html.*;
import net.sf.json.*
import com.gargoylesoftware.htmlunit.WebClient
def baseUrl = 'https://releases.hashicorp.com'
def json = []
def wc = new WebClient()
HtmlPage p = wc.getPage("${baseUrl}/consul/")
p.getByXPath("//a[@href]").grep { it.hrefAttribute =~ /\/consul\/.*/ }.each {
wc.getPage("${baseUrl}${it.hrefAttribute}").getByXPath("//a[@href]").each {
def m = (it.textContent =~ /consul_.*(\d+.\d+.\d+)_(.*)_(.*).zip/)
if (m) {
def verId = "${m[0][1]}-${m[0][2]}-${m[0][3]}".toString()
json << ["id": verId, "name": "Consul ${m[0][1]} ${m[0][2]} (${m[0][3]})".toString(), "url": "${baseUrl}${it.hrefAttribute}".toString()];
}
}
}
lib.DataWriter.write("com.inneractive.jenkins.plugins.consul.ConsulInstaller",JSONObject.fromObject([list:json]));