Skip to content
Closed
Changes from 3 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 @@ -14,6 +14,7 @@
import hudson.plugins.git.util.GitUtils;
import hudson.slaves.NodeProperty;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import java.util.Objects;
import org.eclipse.jgit.transport.RefSpec;
Expand Down Expand Up @@ -148,7 +149,12 @@ public void decorateCloneCommand(GitSCM scm, Run<?, ?> build, GitClient git, Tas
// in a single job definition.
RemoteConfig rc = scm.getRepositories().get(0);
List<RefSpec> refspecs = rc.getFetchRefSpecs();
cmd.refspecs(refspecs);
List<RefSpec> expandedRefSpecs = new ArrayList<>();
EnvVars env = build.getEnvironment(listener);
for (RefSpec ref : refspecs) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Needs automated tests to confirm:

  • Operating system environment variables (like PATH) are expanded as expected (PATH will generate a nonsense refspec, but it has the benefit of being defined on all supported platforms)
  • Jenkins variables (like GIT_BRANCH) are expanded as expected in a Freestyle project
  • Jenkins token macros (like GIT_REVISION) are expanded as expected in a Freestyle project

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I have added a test file which is running successful tests for "BUILD_ID", "BUILD_NO" and "GIT_COMMIT".
I have two issues here:

  • I can't make a freestyle build with ${PATH} added in the refspec, it fails the build with a "can't file the commitFile in the working directory". Although I have tested this interactively where you can clearly see that the refspec is expanded but the build fails, I still would want your opinion on this.

Screenshot 2020-02-07 at 9 19 29 PM

  • By Jenkins token macros do you mean running a build with parameters? Is that how tokens are used? If yes then how does one set a parameter for a job? Should I put the variable in the EnvVars store?

Copy link
Contributor Author

@rishabhBudhouliya rishabhBudhouliya Feb 7, 2020

Choose a reason for hiding this comment

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

I've seen the Token Macro API but I don't think that serves our purpose here
assertThat(TokenMacro.expandAll(build2, listener, "${GIT_REVISION}"), is(sha1String));

Copy link
Contributor Author

Choose a reason for hiding this comment

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

After doing some RCA I found out that adding ${PATH} to refspec would make it illegal, hence the job will fail before doing anything else.

Copy link
Member

Choose a reason for hiding this comment

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

I can't make a freestyle build with ${PATH} added in the refspec, it fails the build with a "can't file the commitFile in the working directory"

How did you tried? Just adding ${PATH} to permuteRefSpecVariable?

I'd also like to know how this PR behaves with job parameters (https://wiki.jenkins.io/display/JENKINS/Define+Parameters)

expandedRefSpecs.add(new RefSpec(env.expand(ref.toString())));
}
cmd.refspecs(expandedRefSpecs);
}
cmd.timeout(timeout);

Expand Down