问题
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