问题
I was trying to configure JobDSL plugin in Jenkins to automatically create Jenkins jobs for all repos in my Github account, and tried the following code snippet but it doesn't show any repos using Github API URL, so I found the issue was in authentication. Now I've configured the Github credentials in the Jenkins global configurations. My question is how can I add this credentials in the code snippet to authenticate.
def organization = 'mygitorg'
repoApi = new URL("https://api.github.com/orgs/${organization}/repos")
repos = new groovy.json.JsonSlurper().parse(repoApi.newReader())
repos.each {
def repoName = it.name
job {
name "${organization}-${repoName}".replaceAll('/','-')
scm {
git("git://github.com/${organization}/${repoName}.git", "master")
}
}
}
来源:https://stackoverflow.com/questions/61156222/how-to-create-jenkins-jobs-automatically-in-using-jobdsl-plugin