【问题标题】:jenkins: configure github project in jenkins pipeline programmatically via groovy scriptjenkins:通过 groovy 脚本以编程方式在 jenkins 管道中配置 github 项目
【发布时间】:2019-11-08 12:02:16
【问题描述】:

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

这运行良好。但是现在,我也喜欢以编程方式配置管道的其他部分,我不知道从哪里开始。例如,我喜欢配置 repo 的 github url,我可以在以下位置手动配置:

我也喜欢自动检查构建触发器,但不知道在哪里搜索正确的 groovy 配置命令:(如您所见)

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')
        }
    }
}

【问题讨论】:

    标签: jenkins github groovy


    【解决方案1】:

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

     properties{
       githubProjectUrl("url to repo")
     }
    

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-03-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多