Skip to content

Commit 98b5da4

Browse files
committed
feat: Add support for gerrit changes for download Jenkins file
We want to support the verification pipeline when the Jenkinsfile is part of the modification itself. This allow to test the pipeline on any project and test it. Signed-off-by: Michael Trimarchi <michael@amarulasolutions.com>
1 parent 93c9316 commit 98b5da4

3 files changed

Lines changed: 12 additions & 0 deletions

File tree

src/main/java/hudson/plugins/git/BranchSpec.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,9 @@ private Pattern getPattern(EnvVars env, String repositoryName) {
159159
String regexSubstring = expandedName.substring(1, expandedName.length());
160160
return Pattern.compile(regexSubstring);
161161
}
162+
if (expandedName.startsWith("refs/changes/")) {
163+
return Pattern.compile(Pattern.quote(expandedName));
164+
}
162165
if (repositoryName != null) {
163166
// remove the "refs/.../" stuff from the branch-spec if necessary
164167
String pattern = cutRefs(expandedName)

src/main/java/jenkins/plugins/git/GitSCMFileSystem.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -267,6 +267,9 @@ public boolean supports(SCM source) {
267267
|| gscm.getBranches().get(0).getName().matches(
268268
"^((\\Q" + Constants.R_TAGS + "\\E.*)|([^/]+)|(\\*/[^/*]+(/[^/*]+)*))$"
269269
)
270+
|| gscm.getBranches().get(0).getName().matches(
271+
"^((\\Qrefs/changes/\\E.*)|([^/]+)|(\\*/[^/*]+(/[^/*]+)*))$"
272+
)
270273
);
271274
// we only support where the branch spec is obvious and not a wildcard
272275
}
@@ -306,6 +309,8 @@ static HeadNameResult calculate(@NonNull BranchSpec branchSpec,
306309
String prefix = Constants.R_HEADS;
307310
if (branchSpecExpandedName.startsWith(Constants.R_TAGS)) {
308311
prefix = Constants.R_TAGS;
312+
} else if (branchSpecExpandedName.startsWith("refs/changes")) {
313+
prefix = "refs/changes/";
309314
}
310315

311316
String headName;

src/main/resources/hudson/plugins/git/BranchSpec/help-name.html

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,10 @@
4747
Tracks/checks out the specified tag.<br/>
4848
E.g. <code>refs/tags/git-2.3.0</code>
4949
</li>
50+
<li> <strong><code>refs/changes/&lt;gerritChange&gt;</code></strong><br/>
51+
Tracks/checks out the specified gerrit change.<br/>
52+
E.g. <code>refs/changes/91/45391/1</code>
53+
</li>
5054
<li> <strong><code>&lt;commitId&gt;</code></strong><br/>
5155
Checks out the specified commit.<br/>
5256
E.g. <code>5062ac843f2b947733e6a3b105977056821bd352</code>, <code>5062ac84</code>, ...

0 commit comments

Comments
 (0)