How create and configure a new Jenkins Job using groovy?

前端 未结 4 1370
被撕碎了的回忆
被撕碎了的回忆 2020-12-15 08:22

There are a lot of examples of groovy scripts (http://scriptlerweb.appspot.com/catalog/list) however I have found no examples of new job creation. Is there a good example on

4条回答
  •  执念已碎
    2020-12-15 09:03

    The Jenkins plugin Job DSL Plugin can add steps into jobs to create/modify existing jobs.

    Here is the example from the plugin's web site, that creates a job for each branch in a git repository:

    def project = 'quidryan/aws-sdk-test'
    def branchApi = new URL("https://api.github.com/repos/${project}/branches")
    def branches = new groovy.json.JsonSlurper().parse(branchApi.newReader())
    branches.each {
        def branchName = it.name
        def jobName = "${project}-${branchName}".replaceAll('/','-')
        job(jobName) {
            scm {
                git("git://github.com/${project}.git", branchName)
            }
            steps {
                maven("test -Dproject.name=${project}/${branchName}")
            }
        }
    }
    

提交回复
热议问题