| 12345678910111213141516171819202122232425262728293031323334353637383940414243 |
- def server = GOGS_SERVER
- def apikey = GOGS_API_KEY
- def api = "${server}/api/v1"
- def restExists(url) {
- def u = new URL(url)
- def req = u.openConnection();
- def getRC = req.getResponseCode();
- if(getRC.equals(200)) {
- return true;
- }
- return false;
- }
- def restJSONGet(url) {
- def u = new URL(url)
- return new groovy.json.JsonSlurper().parse(u.newReader())
- }
- def projects = restJSONGet("${api}/user/repos?token=${apikey}")
- projects.each {
- def project = it.full_name
- def repo = it.clone_url
- def jenkinsFile = restExists("${api}/repos/${project}/raw/master/Jenkinsfile?token=${apikey}")
- def jobName = "${JOB_PREFIX}${project}".replaceAll('/','-')
- if (jenkinsFile) {
- multibranchPipelineJob(jobName) {
- description("Pipeline for $repo")
- branchSources {
- git {
- remote(repo)
- credentialsId(GOGS_CREDENTIALS)
- }
- }
- orphanedItemStrategy {
- discardOldItems {
- numToKeep(10)
- }
- }
- }
- }
- }
|