How to create Jenkins jobs automatically in using JobDSL plugin

隐身守侯 提交于 2021-02-11 17:10:19

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!