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

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -94,18 +94,19 @@ class GerritContext implements Context {
/**
* Specifies on which Gerrit projects to trigger a build on.
*/
void project(String projectName, List<String> branches) {
void project(String projectName, List<String> branches, List<String> filePaths = []) {
projects << [
new GerritSpec(projectName),
branches.collect { new GerritSpec(it) }
branches.collect { new GerritSpec(it) },
filePaths.collect { new GerritSpec(it) }
]
}

/**
* Specifies on which Gerrit projects to trigger a build on.
*/
void project(String projectName, String branch) {
project(projectName, [branch])
void project(String projectName, String branch, String filePath = '') {
project(projectName, [branch], [filePath].findAll())
}

static class GerritSpec {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,24 +53,40 @@ class TriggerContext extends ItemTriggerContext {
GerritContext gerritContext = new GerritContext()
ContextHelper.executeInContext(contextClosure, gerritContext)

String filePathNodeName = 'com.sonyericsson.hudson.plugins.gerrit.trigger.hudsontrigger.data.FilePath'
String branchNodeName = 'com.sonyericsson.hudson.plugins.gerrit.trigger.hudsontrigger.data.Branch'
String gerritProjectNodeName = 'com.sonyericsson.hudson.plugins.gerrit.trigger.hudsontrigger.data.GerritProject'
String gerritTriggerNodeName = 'com.sonyericsson.hudson.plugins.gerrit.trigger.hudsontrigger.GerritTrigger'

NodeBuilder nodeBuilder = new NodeBuilder()
Node gerritNode = nodeBuilder.'com.sonyericsson.hudson.plugins.gerrit.trigger.hudsontrigger.GerritTrigger' {
Node gerritNode = nodeBuilder."$gerritTriggerNodeName" {
spec ''
if (gerritContext.projects) {
gerritProjects {
gerritContext.projects.each { GerritSpec project, List<GerritSpec> brancheSpecs ->
'com.sonyericsson.hudson.plugins.gerrit.trigger.hudsontrigger.data.GerritProject' {
compareType project.type
pattern project.pattern
branches {
brancheSpecs.each { GerritSpec branch ->
'com.sonyericsson.hudson.plugins.gerrit.trigger.hudsontrigger.data.Branch' {
compareType branch.type
pattern branch.pattern
gerritContext.projects.each {
GerritSpec project, List<GerritSpec> brancheSpecs, List<String> filePathsSpec ->
"$gerritProjectNodeName" {
compareType project.type
pattern project.pattern
branches {
brancheSpecs.each { GerritSpec branch ->
"$branchNodeName" {
compareType branch.type
pattern branch.pattern
}
}
}
if (filePathsSpec) {
filePaths {
filePathsSpec.each { GerritSpec path ->
"$filePathNodeName" {
compareType path.type
pattern path.pattern
}
}
}
}
}
}
}
}
}
Expand Down Expand Up @@ -146,8 +162,8 @@ class TriggerContext extends ItemTriggerContext {
void upstream(String projects, String threshold = 'SUCCESS') {
Preconditions.checkNotNullOrEmpty(projects, 'projects must be specified')
Preconditions.checkArgument(
Threshold.THRESHOLD_COLOR_MAP.containsKey(threshold),
"threshold must be one of ${Threshold.THRESHOLD_COLOR_MAP.keySet().join(', ')}"
Threshold.THRESHOLD_COLOR_MAP.containsKey(threshold),
"threshold must be one of ${Threshold.THRESHOLD_COLOR_MAP.keySet().join(', ')}"
)

triggerNodes << new NodeBuilder().'jenkins.triggers.ReverseBuildTrigger' {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ class TriggerContextSpec extends Specification {
draftPublished()
}
project('reg_exp:myProject', ['ant:feature-branch', 'plain:origin/refs/mybranch']) // full access
project('test-project', '**') // simplified
project('test-project', '**', 'plain:project1/**') // simplified
configure { node ->
node / gerritBuildSuccessfulVerifiedValue << '10'
}
Expand All @@ -109,11 +109,17 @@ class TriggerContextSpec extends Specification {
compareType[0].value() == 'ANT'
pattern[0].value() == 'feature-branch'
}
filePaths.size() == 0
}
with(children()[1]) {
compareType[0].value() == 'PLAIN'
pattern[0].value() == 'test-project'
branches[0].children().size() == 1
with(filePaths[0].children()[0]) {
name() == 'com.sonyericsson.hudson.plugins.gerrit.trigger.hudsontrigger.data.FilePath'
compareType[0].value() == 'PLAIN'
pattern[0].value() == 'project1/**'
}
}
}
}
Expand Down