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) { pipelineJob(jobName) { triggers { scm('@hourly') } description("Pipeline for $repo") quietPeriod(5*60) environmentVariables(FOO: 'bar', TEST: '123') definition { cpsScm { scm { git { remote { url(repo) credentials(GOGS_CREDENTIALS) } branches('master', '**/feature*') scriptPath('Jenkinsfile') extensions { } // required as otherwise it may try to tag the repo, which you may not want } } } } wrappers { buildName('#${BUILD_NUMBER} on ${ENV,var="BRANCH"}') } } } }