Open teeks99 opened 7 years ago
I am taking a wild guess at how you might configure this. Try:
options {
gitLabConnection('<your-gitlab-connection-name')
gitlabCommitStatus(name: 'jenkins')
noteRegex('This is the string which should trigger a build')
}
I was also looking for the more advanced configuration of the GitLab triggers through a declarative pipeline when I stumbled across another issue (#547) that seemed to have a whole lot of the settings needed (but in a Groovy pipeline syntax).
I was able to synthesize it into the following, which definitely seems to work for a pipeline job (not multi-branch). In other words, it sets all of the GitLab trigger fields the way that you'd expect:
triggers {
gitlab(
triggerOnPush: false,
triggerOnMergeRequest: true, triggerOpenMergeRequestOnPush: "never",
triggerOnNoteRequest: true,
noteRegex: "Jenkins please retry a build",
skipWorkInProgressMergeRequest: true,
ciSkip: false,
setBuildDescription: true,
addNoteOnMergeRequest: true,
addCiMessage: true,
addVoteOnMergeRequest: true,
acceptMergeRequestOnSuccess: false,
branchFilterType: "NameBasedFilter",
includeBranchesSpec: "release/qat",
excludeBranchesSpec: "",
secretToken: "abcdefghijklmnopqrstuvwxyz0123456789ABCDEF")
}
That said, it would be nice to see this properly documented so that we didn't need to guess at the correct parameters
@teeks99 can you try @mginou's solution? If that works for you, either I'll update the docs or, preferably, one of you can :)
I can verify adding these two lines to my Jenkins file triggers { gitlab ( ...
triggerOnNoteRequest: true,
noteRegex: "Jenkins please retry a build"
Does cause it to build when the expected note is added, in a pipeline job.
However it does not seem to be working in a multibranch pipeline. Is that just a limitation of the less useful triggers in multibranch? Could we add a post trigger API call that looks for new notes related to the respective branches?
This current state should probably be noted in the docs. I don't know if we'd want a separate issue for the multibranch case.
@teeks99 yeah this is interesting. My understanding of our support for multibranch is that we just trigger the build and branch indexing, but no parameters are passed to that job type because they aren't really needed. So I think the multibranch job doesn't unpack the JSON much. This might have to be a feature request, if it's even possible.
If someone wants to offer a PR on the README with an explanation of how to make this work in regular Pipeline jobs, that would be nice :)
Still a feature request to support this in Multibranch, but I updated the doc for regular Declarative jobs.
Issue
When running a freestyle build, this plugin provides a field titled "Comment for triggering a build" that consumes the notes in a merge request and, if they match the provided regex, starts a new jenkins build against the same commit.
There doesn't appear to be the same feature in the pipeline declarative syntax (unless I'm missing it...if so then this issue could be re-directed to simply improve the documentation), or the procedural syntax for that matter.
In the declarative example in the readme there is a section:
To solve this issue, we could just update it so that the following works:
Context