how to add gerrit-trigger events inside Jenkins pipeline code, inside Jenkinsfile

此生再无相见时 提交于 2020-01-04 05:45:07

问题


I would like to add gerrit trigger events inside Jenkinsfile, like we have in JobDSL,

        triggers {
            upstream('pipeline_properties', 'UNSTABLE')
            gerrit {
                events {
                    refUpdated()
                }
                project('reg_exp:jenkins', ["plain:${jenkins_branch}"])
            }
        }

Is this something possible in pipeline code, could able to find some things like cron and stuffs under triggers but not able to get a reference how to add the gerrit-trigger event inside.


回答1:


Here is one working Jenkinsfile covers the gerrit trigger event part, see reference below the code segment

BuildDiscarderProperty & SCMTrigger are used for sample as well.

#!/usr/bin/env groovy          
properties(
    [
        [
            $class: 'BuildDiscarderProperty',
            strategy: [$class: 'LogRotator', numToKeepStr: '10']
        ],
        pipelineTriggers([
            [
                $class: 'SCMTrigger',
                scmpoll_spec: "H H 1,15 1-11 *"
            ],
            [
                $class: 'GerritTrigger', gerritProjects: [
                    [
                        $class: "GerritProject", 
                        compareType: "REG_EXP",
                        pattern: "jenkins",
                        branches: [
                            [
                                $class: "Branch",
                                pattern: "\${jenkins_branch}"
                            ]
                        ]
                    ]
                ],
                triggerOnEvents: [
                    [$class: "PluginRefUpdatedEvent"]
                ]
            ]
        ])
    ]
)
node {
    echo 'Hello World'
}  

Useful reference

  • gerrit trigger source code@github
  • Hints for pipelineTriggers https://issues.jenkins-ci.org/browse/JENKINS-37731

config.xml under JENKINS_HOME job directory is used for debug



来源:https://stackoverflow.com/questions/46241935/how-to-add-gerrit-trigger-events-inside-jenkins-pipeline-code-inside-jenkinsfil

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