jenkins:通过groovy脚本以编程方式在jenkins管道中配置github项目

时间:2019-06-26 13:54:52

标签: jenkins github groovy

嘿,我想以编程方式配置带有管道作业的Jenkins-管道,您可以在https://github.com/divramod/pipeline-testing/blob/master/cicd/jobs/master.jenkins

中找到

运行正常。但是现在,我还希望以编程方式配置管道的其他部分,而且我不知道从哪里开始。例如,我想配置仓库的github URL,我可以在以下位置手动进行操作:

enter image description here

我还喜欢自动检查Build Trigger,但是不知道在哪里搜索正确的常规配置命令:(如您在此处看到的那样)

enter image description here

pipelineJob('master pipe') {
    displayName('Master pipe')

    logRotator {
        numToKeep(10)
        daysToKeep(30)
    }

    configure { project ->
        project / 'properties' / 'org.jenkinsci.plugins.workflow.job.properties.DurabilityHintJobProperty' {
            hint('PERFORMANCE_OPTIMIZED')
        }
    }

    definition {
        cpsScm {
            scm {
                git {
                    remote {
                        url('git@github.com:divramod/pipeline-testing.git')
                        credentials('jenkins')
                    }
                    branches('*/master')
                }
            }
            scriptPath('cicd/pipelines/master.jenkins')
        }
    }
}

1 个答案:

答案 0 :(得分:1)

您可以在pipelineJob指令中添加以下块以添加github项目URL。

 properties{
   githubProjectUrl("url to repo")
 }

要添加触发器,您可以探索dynamic DSL