|
@@ -0,0 +1,34 @@
|
|
|
|
|
+
|
|
|
|
|
+def resolver = build.buildVariableResolver
|
|
|
|
|
+def server = resolver.resolve("GOGS_SERVER") + "/api/v1"
|
|
|
|
|
+def apikey = resolver.resolve("GOGS_API_KEY")
|
|
|
|
|
+def root = "${server}/api/v1"
|
|
|
|
|
+
|
|
|
|
|
+def restExists(url) {
|
|
|
|
|
+ def u = new URL(url)
|
|
|
|
|
+ def req = u.openConnection();
|
|
|
|
|
+ req.setRequestMethod("OPTIONS")
|
|
|
|
|
+ def getRC = req.getResponseCode();
|
|
|
|
|
+ if(getRC.equals(200)) {
|
|
|
|
|
+ return true;
|
|
|
|
|
+ }
|
|
|
|
|
+ return false;
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
|
|
+def restJSONGet(url) {
|
|
|
|
|
+ def u = new URL("${root}/user/repos?token=${apikey})
|
|
|
|
|
+ return new groovy.json.JsonSlurper().parse(u.newReader())
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
|
|
+def projects = restJSONGet("${root}/user/repos?token=${apikey})
|
|
|
|
|
+
|
|
|
|
|
+projects.each {
|
|
|
|
|
+ def project = it.full_name
|
|
|
|
|
+ def branches = restJSONGet("${root}/repos/${project}/branches")
|
|
|
|
|
+ branches.each {
|
|
|
|
|
+ def branchName = it.name
|
|
|
|
|
+ def jenkinsFile = restExists("${root}/repos/${project}/raw/${branchName}/Jenkinsfile?token=$apikey}")
|
|
|
|
|
+ def jobName = "${project}".replaceAll('/','-')
|
|
|
|
|
+ println("${project}/${branchName} - ${jobName} / hasFile ${jenkinsFile}"
|
|
|
|
|
+ }
|
|
|
|
|
+}
|