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

JENKINS-58313 Expose source commit #163

Closed
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion pom.xml
Expand Up @@ -69,7 +69,7 @@
<changelist>-SNAPSHOT</changelist>
<jenkins.version>2.138.4</jenkins.version>
<java.level>8</java.level>
<scm-api.version>2.4.1</scm-api.version>
<scm-api.version>2.4.2-SNAPSHOT</scm-api.version>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Incrementals

<git-plugin.version>3.10.0</git-plugin.version>
</properties>

Expand Down
6 changes: 5 additions & 1 deletion src/main/java/jenkins/branch/BranchNameContributor.java
Expand Up @@ -32,12 +32,13 @@
import hudson.model.TaskListener;
import java.io.IOException;
import java.util.Date;
import jenkins.scm.api.SCMHeadOrigin;
import jenkins.scm.api.SCMHead;
import jenkins.scm.api.SCMHeadOrigin;
import jenkins.scm.api.metadata.ContributorMetadataAction;
import jenkins.scm.api.metadata.ObjectMetadataAction;
import jenkins.scm.api.mixin.ChangeRequestSCMHead;
import jenkins.scm.api.mixin.ChangeRequestSCMHead2;
import jenkins.scm.api.mixin.ChangeRequestSCMHead3;
import jenkins.scm.api.mixin.TagSCMHead;

/**
Expand Down Expand Up @@ -68,6 +69,9 @@ public void buildEnvironmentFor(Job j, EnvVars envs, TaskListener listener) thro
if (head instanceof ChangeRequestSCMHead2) {
envs.putIfNotNull("CHANGE_BRANCH", ((ChangeRequestSCMHead2) head).getOriginName());
}
if (head instanceof ChangeRequestSCMHead3) {
envs.putIfNotNull("CHANGE_BRANCH_COMMIT_ID", ((ChangeRequestSCMHead3) head).getSourceCommitId());
}
SCMHeadOrigin origin = head.getOrigin();
if (origin instanceof SCMHeadOrigin.Fork) {
envs.putIfNotNull("CHANGE_FORK", ((SCMHeadOrigin.Fork) origin).getName());
Expand Down
4 changes: 4 additions & 0 deletions src/test/java/jenkins/branch/BranchNameContributorTest.java
Expand Up @@ -122,6 +122,7 @@ public void buildEnvironmentFor() throws Exception {
is("CHANGE_TITLE"),
is("CHANGE_URL"),
is("CHANGE_BRANCH"),
is("CHANGE_BRANCH_COMMIT_ID"),
is("CHANGE_AUTHOR"),
is("CHANGE_AUTHOR_EMAIL"),
is("CHANGE_AUTHOR_DISPLAY_NAME")
Expand All @@ -130,6 +131,7 @@ public void buildEnvironmentFor() throws Exception {
assertThat(env.get("CHANGE_ID"), is(cr1Num.toString()));
assertThat(env.get("CHANGE_TARGET"), is("master"));
assertThat(env.get("CHANGE_BRANCH"), is("CR-" + cr1Num));
assertThat(env.get("CHANGE_BRANCH_COMMIT_ID"), is("sha" + cr1Num));
assertThat(env.get("CHANGE_TITLE"), is("Change request #" + cr1Num));
assertThat(env.get("CHANGE_URL"), is("http://changes.example.com/" + cr1Num));
assertThat(env.get("CHANGE_AUTHOR"), is("bob"));
Expand All @@ -145,6 +147,7 @@ public void buildEnvironmentFor() throws Exception {
is("CHANGE_TITLE"),
is("CHANGE_URL"),
is("CHANGE_BRANCH"),
is("CHANGE_BRANCH_COMMIT_ID"),
is("CHANGE_FORK"),
is("CHANGE_AUTHOR"),
is("CHANGE_AUTHOR_EMAIL"),
Expand All @@ -154,6 +157,7 @@ public void buildEnvironmentFor() throws Exception {
assertThat(env.get("CHANGE_ID"), is(cr2Num.toString()));
assertThat(env.get("CHANGE_TARGET"), is("master"));
assertThat(env.get("CHANGE_BRANCH"), is("CR-" + cr2Num));
assertThat(env.get("CHANGE_BRANCH_COMMIT_ID"), is("sha" + cr2Num));
assertThat(env.get("CHANGE_FORK"), is("fork"));
assertThat(env.get("CHANGE_TITLE"), is("Change request #" + cr2Num));
assertThat(env.get("CHANGE_URL"), is("http://changes.example.com/" + cr2Num));
Expand Down