本文介绍了如何在Jenkinsfile内的Jenkins管道代码内添加gerrit-trigger事件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想像在JobDSL中一样在Jenkinsfile中添加gerrit触发事件,

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}"])
            }
        }

在管道代码中是否有这种可能,能够在触发器下找到诸如cron和东西之类的东西,但无法获得有关如何在其中添加gerrit-trigger事件的参考.

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.

推荐答案

这里是一个有效的Jenkinsfile,涵盖了Gerrit触发事件部分,请参见代码段下方的参考

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

BuildDiscarderProperty& SCMTrigger也用于样本.

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

有用的参考

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

config.xml用于调试

这篇关于如何在Jenkinsfile内的Jenkins管道代码内添加gerrit-trigger事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-24 19:19