Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add path selection for gerrit trigger #749

Conversation

alien11689
Copy link

No description provided.

@alien11689 alien11689 force-pushed the AddPathSelectionForGerritTrigger branch from 2838097 to 336134d Compare February 15, 2016 11:03
@alien11689 alien11689 force-pushed the AddPathSelectionForGerritTrigger branch from 336134d to 74b41d6 Compare February 15, 2016 11:56
@jenkinsadmin
Copy link
Member

Thank you for this pull request! Please check this document for how the Jenkins project handles pull requests.

@daspilker
Copy link
Member

I tried to do a review, but I figured out that I need a running Gerrit instance to test this. Can you confirm? Do you have a public instance that I can use for testing?

@alien11689
Copy link
Author

Hi,
Unfortunatelly i have not such gerrit instance. Gerrit in my company is private and we cannot exposed it.

But I have working configuration xml from jenkins:

    <com.sonyericsson.hudson.plugins.gerrit.trigger.hudsontrigger.GerritTrigger plugin="gerrit-trigger@2.13.0">
      <gerritProjects>
        <com.sonyericsson.hudson.plugins.gerrit.trigger.hudsontrigger.data.GerritProject>
          <compareType>ANT</compareType>
          <pattern>projectX</pattern>
          <branches>
            <com.sonyericsson.hudson.plugins.gerrit.trigger.hudsontrigger.data.Branch>
              <compareType>ANT</compareType>
              <pattern>**</pattern>
            </com.sonyericsson.hudson.plugins.gerrit.trigger.hudsontrigger.data.Branch>
          </branches>
          <filePaths>
            <com.sonyericsson.hudson.plugins.gerrit.trigger.hudsontrigger.data.FilePath>
              <compareType>ANT</compareType>
              <pattern>modules/module1/**</pattern>
            </com.sonyericsson.hudson.plugins.gerrit.trigger.hudsontrigger.data.FilePath>
          </filePaths>
        </com.sonyericsson.hudson.plugins.gerrit.trigger.hudsontrigger.data.GerritProject>
      </gerritProjects>
      <triggerOnEvents>
        <com.sonyericsson.hudson.plugins.gerrit.trigger.hudsontrigger.events.PluginPatchsetCreatedEvent>
          <excludeDrafts>false</excludeDrafts>
          <excludeTrivialRebase>false</excludeTrivialRebase>
          <excludeNoCodeChange>false</excludeNoCodeChange>
        </com.sonyericsson.hudson.plugins.gerrit.trigger.hudsontrigger.events.PluginPatchsetCreatedEvent>
        <com.sonyericsson.hudson.plugins.gerrit.trigger.hudsontrigger.events.PluginChangeRestoredEvent/>
        <com.sonyericsson.hudson.plugins.gerrit.trigger.hudsontrigger.events.PluginDraftPublishedEvent/>
        <com.sonyericsson.hudson.plugins.gerrit.trigger.hudsontrigger.events.PluginChangeMergedEvent/>
      </triggerOnEvents>
    </com.sonyericsson.hudson.plugins.gerrit.trigger.hudsontrigger.GerritTrigger>

@alien11689
Copy link
Author

There is also available docker image with gerrit: https://hub.docker.com/r/openfrontier/gerrit/

@daspilker
Copy link
Member

I tried the Docker image, but got lost in authentication problems between Jenkins and Gerrit...

I always do some manual testing for a new feature before merging to see if there are any typos or copy&paste error in the generated XML. If I can't do the testing, I'm not going to merge a feature.

But there is a way out. This triggered me to take a look at the new Structs Plugin for generating DSLs. I plan to integrate generic DSL support for any plugin with the help of the Structs plugin, see #816. Support for the new @Symbol annotation got already merged in the Gerrit Trigger plugin, see jenkinsci/gerrit-trigger-plugin#280.

This will enable the following generic Job DSL syntax for the Gerrit trigger, including path selection.

job('example') {
  triggers {
    gerritTrigger {
      gerritProjects {
        gerritProject {
          compareType('ANT')
          pattern('projectX')
          branches {
            branch {
              compareType('ANT')
              pattern('**')
            }
          }
          filePaths {
            filePath {
              compareType('ANT')
              pattern('modules/module1/**')
            }
          }
          disableStrictForbiddenFileVerification(false)
        }
      }
      triggerOnEvents {
        patchsetCreated {
          excludeDrafts(false)
          excludeTrivialRebase(false)
          excludeNoCodeChange(false)
        }
        changeRestored()
        draftPublished()
        changeMerged()
      }      
    }
  }
}

The syntax is a bit different from the built-in syntax, but all options of the Gerrit trigger are supported out-of-the-box.

So the next Job DSL and Gerrit Trigger releases will enable the DSL above. Until then I keep this PR open for reference, but I will close it after the release. The built-in DSL support for the Gerrit trigger will be deprecated in favor for the generic DSL.

@daspilker
Copy link
Member

The example above will work with Job DSL 1.46 and Gerrit Trigger 2.20.0, so I am closing this PR.

@daspilker daspilker closed this May 10, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants