Skip to content

Commit 536b177

Browse files
author
Jeff Knurek
committed
[JENKINS-52490] add more documentation, and test for the new env var
* rename the env var to be aligned with the git description * test isn't working yet as expected, still need more investigation into why Signed-off-by: Jeff Knurek <[email protected]>
1 parent aa8a6ae commit 536b177

File tree

5 files changed

+23
-4
lines changed

5 files changed

+23
-4
lines changed

README.adoc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -468,6 +468,7 @@ GIT_LOCAL_BRANCH:: Name of branch being built without remote name, as in `master
468468
GIT_COMMIT:: SHA-1 of the commit used in this build
469469
GIT_PREVIOUS_COMMIT:: SHA-1 of the commit used in the preceding build of this project
470470
GIT_PREVIOUS_SUCCESSFUL_COMMIT:: SHA-1 of the commit used in the most recent successful build of this project
471+
GIT_COMMIT_TITLE:: The text up to the first blank line in the commit message used in this build
471472

472473
=== System Configuration Variables
473474

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

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,7 @@ public class GitSCM extends GitSCMBackwardCompatibility {
152152
public static final String GIT_LOCAL_BRANCH = "GIT_LOCAL_BRANCH";
153153
public static final String GIT_CHECKOUT_DIR = "GIT_CHECKOUT_DIR";
154154
public static final String GIT_COMMIT = "GIT_COMMIT";
155-
public static final String GIT_COMMIT_MESSAGE = "GIT_COMMIT_MESSAGE";
155+
public static final String GIT_COMMIT_TITLE = "GIT_COMMIT_TITLE";
156156
public static final String GIT_PREVIOUS_COMMIT = "GIT_PREVIOUS_COMMIT";
157157
public static final String GIT_PREVIOUS_SUCCESSFUL_COMMIT = "GIT_PREVIOUS_SUCCESSFUL_COMMIT";
158158

@@ -1203,7 +1203,7 @@ public void checkout(Run<?, ?> build, Launcher launcher, FilePath workspace, Tas
12031203
try {
12041204
String shortMessage = getCommitMessage(listener, git, revToBuild);
12051205
listener.getLogger().println("Commit message: \"" + shortMessage + "\"");
1206-
environment.put(GIT_COMMIT_MESSAGE, shortMessage);
1206+
environment.put(GIT_COMMIT_TITLE, shortMessage);
12071207
} catch (GitException ge) {
12081208
listener.getLogger().println("Exception logging commit message for " + revToBuild + ": " + ge.getMessage());
12091209
}
@@ -1250,7 +1250,6 @@ private String getCommitMessage(TaskListener listener, GitClient git, final Buil
12501250
return "";
12511251
}
12521252

1253-
12541253
/**
12551254
* Build up change log from all the branches that we've merged into {@code revToBuild}.
12561255
*

src/main/resources/hudson/plugins/git/GitSCM/buildEnv.groovy

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ package hudson.plugins.git.GitSCM
33
def l = namespace(lib.JenkinsTagLib)
44

55
// TODO handle GitSCMExtension.populateEnvironmentVariables somehow, say by optionally including GitSCMExtension/buildEnv.groovy; though GIT_{COMMITTER,AUTHOR}_{NAME,EMAIL} are only overridden by UserIdentity
6-
['GIT_COMMIT', 'GIT_PREVIOUS_COMMIT', 'GIT_PREVIOUS_SUCCESSFUL_COMMIT', 'GIT_BRANCH', 'GIT_LOCAL_BRANCH', 'GIT_CHECKOUT_DIR', 'GIT_URL', 'GIT_COMMITTER_NAME', 'GIT_AUTHOR_NAME', 'GIT_COMMITTER_EMAIL', 'GIT_AUTHOR_EMAIL'].each {name ->
6+
['GIT_COMMIT', 'GIT_PREVIOUS_COMMIT', 'GIT_PREVIOUS_SUCCESSFUL_COMMIT', 'GIT_BRANCH', 'GIT_LOCAL_BRANCH', 'GIT_CHECKOUT_DIR', 'GIT_URL', 'GIT_COMMITTER_NAME', 'GIT_AUTHOR_NAME', 'GIT_COMMITTER_EMAIL', 'GIT_AUTHOR_EMAIL', 'GIT_COMMIT_TITLE'].each {name ->
77
l.buildEnvVar(name: name) {
88
raw(_("${name}.blurb"))
99
}

src/main/resources/hudson/plugins/git/GitSCM/buildEnv.properties

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
GIT_COMMIT.blurb=The commit hash being checked out.
22
GIT_PREVIOUS_COMMIT.blurb=The hash of the commit last built on this branch, if any.
33
GIT_PREVIOUS_SUCCESSFUL_COMMIT.blurb=The hash of the commit last successfully built on this branch, if any.
4+
GIT_COMMIT_TITLE.blurb=The text up to the first blank line in a commit message is treated as the commit title.
45
GIT_BRANCH.blurb=The remote branch name, if any.
56
GIT_LOCAL_BRANCH.blurb=The local branch name being checked out, if applicable.
67
GIT_CHECKOUT_DIR.blurb=The directory that the repository will be checked out to. This contains the value set in Checkout to a sub-directory, if used.

src/test/java/hudson/plugins/git/GitSCMTest.java

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2699,6 +2699,24 @@ public void testCommitMessageIsPrintedToLogs() throws Exception {
26992699
assertThat(values, hasItem("Commit message: \"test commit\""));
27002700
}
27012701

2702+
@Test
2703+
public void testCommitMessageIsEnvVar() throws Exception {
2704+
String title = "test commit";
2705+
sampleRepo.init();
2706+
sampleRepo.write("file", "v1");
2707+
sampleRepo.git("commit", "--all", "--message", title);
2708+
FreeStyleProject p = setupSimpleProject("master");
2709+
Run<?,?> run = rule.buildAndAssertSuccess(p);
2710+
TaskListener mockListener = Mockito.mock(TaskListener.class);
2711+
Mockito.when(mockListener.getLogger()).thenReturn(Mockito.spy(StreamTaskListener.fromStdout().getLogger()));
2712+
2713+
p.getScm().checkout(run, new Launcher.LocalLauncher(listener),
2714+
new FilePath(run.getRootDir()).child("tmp-" + "master"),
2715+
mockListener, null, SCMRevisionState.NONE);
2716+
2717+
assertEquals("Commit message should be an env var", getEnvVars(p), title);
2718+
}
2719+
27022720
/**
27032721
* Method performs HTTP get on "notifyCommit" URL, passing it commit by SHA1
27042722
* and tests for build data consistency.

0 commit comments

Comments
 (0)