jenkinsci / gitlab-plugin

A Jenkins plugin for interfacing with GitLab
https://plugins.jenkins.io/gitlab-plugin/
GNU General Public License v2.0
1.43k stars 612 forks source link

Feature Request: Declaritive trigger for notes (in merge requests) #541

Open teeks99 opened 7 years ago

teeks99 commented 7 years ago

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:

triggers {
    gitlab(triggerOnPush: true, triggerOnMergeRequest: true, branchFilterType: 'All')
}

To solve this issue, we could just update it so that the following works:

triggers {
    gitlab(triggerOnPush: true, triggerOnMergeRequest: true, triggerOnNote: 'regex to use', branchFilterType: 'All')
}

Context

omehegan commented 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')
    }
mginou commented 7 years ago

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

omehegan commented 7 years ago

@teeks99 can you try @mginou's solution? If that works for you, either I'll update the docs or, preferably, one of you can :)

teeks99 commented 7 years ago

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.

omehegan commented 7 years ago

@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 :)

omehegan commented 6 years ago

Still a feature request to support this in Multibranch, but I updated the doc for regular Declarative jobs.