question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Expansion of ${sha1} in Branch specifier not working

See original GitHub issue

I am trying to set up the Github Pull Request Builder plugin for our Jenkins server, however sadly the ${sha1} expansion in the Branch Specifier does not seem to be expanded before the git command is executed.

I can see from the “Console Output” that the ${sha1} is unexpanded in the resulting git command which means that the build fails immediately.

Some things I noticed:

  1. sha1 is included and seems to have the right value in the “Parameters” section of the build
  2. the Jenkins wiki page for GHPRB at https://wiki.jenkins.io/display/JENKINS/GitHub+pull+request+builder+plugin lists sha1 among the “useful environment variables” that are made available by the plugin
  3. the “Branch Specifier” part of the “Pipeline” section in the job’s configuration mentions that environment variables should be expandable

So based on the above, everything seems like it should work, except it doesn’t.

Versions:

  • Jenkins 2.60.3
  • Github API plugin 1.86
  • Github plugin 1.28.0
  • Git plugin 3.5.1
  • Credentials plugin 2.1.14
  • Plain Credentials Plugin 1.4
  • Github Pull Request Builder Plugin 1.39.0

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:7 (1 by maintainers)

github_iconTop GitHub Comments

46reactions
dylexcommented, Dec 7, 2017

For the record, I had this same problem, which looks like this:

hudson.plugins.git.GitException: Command "git fetch --tags --progress origin +refs/heads/${sha1}:refs/remotes/origin/${sha1} --prune" returned status code 128:
stdout: 
stderr: fatal: Couldn't find remote ref refs/heads/${sha1}
Unexpected end of command stream

	at org.jenkinsci.plugins.gitclient.CliGitAPIImpl.launchCommandIn(CliGitAPIImpl.java:1970)
	at org.jenkinsci.plugins.gitclient.CliGitAPIImpl.launchCommandWithCredentials(CliGitAPIImpl.java:1689)
	at org.jenkinsci.plugins.gitclient.CliGitAPIImpl.access$300(CliGitAPIImpl.java:71)
	at org.jenkinsci.plugins.gitclient.CliGitAPIImpl$1.execute(CliGitAPIImpl.java:380)
	at jenkins.plugins.git.GitSCMFileSystem$BuilderImpl.build(GitSCMFileSystem.java:351)
	at jenkins.scm.api.SCMFileSystem.of(SCMFileSystem.java:196)
	at jenkins.scm.api.SCMFileSystem.of(SCMFileSystem.java:172)
	at org.jenkinsci.plugins.workflow.cps.CpsScmFlowDefinition.create(CpsScmFlowDefinition.java:99)
	at org.jenkinsci.plugins.workflow.cps.CpsScmFlowDefinition.create(CpsScmFlowDefinition.java:59)
	at org.jenkinsci.plugins.workflow.job.WorkflowRun.run(WorkflowRun.java:262)
	at hudson.model.ResourceController.execute(ResourceController.java:97)
	at hudson.model.Executor.run(Executor.java:421)

And worked around it by disabling “lightweight checkout” in the pipeline config.

0reactions
reach2jeyancommented, Sep 28, 2019

@dylex Sometimes smallest things in life gives you Nirvana . Thanks a ton

Read more comments on GitHub >

github_iconTop Results From Across the Web

Jenkins Pull Request builder ignoring branches with ${sha1}
It appears, based on the refspec of +refs/pull/*:refs/remotes/origin/pr/* that you want this project to build pull requests only.
Read more >
Single commit checkouts don't work - Jenkins Jira
I can't duplicate the problem you've described. I created a multi-configuration job in my test environment which successfully performs a checkout of a...
Read more >
git-plugin fails to expand variables in refspec on initial clone
A sure way to trigger the bug is to enable both "Honor refspec on initial clone" and "Wipe out repository & force clone"....
Read more >
Bug 487703 - Pack expansion in base specifier (Ia6e4626d) · Gerrit ...
Bug 487703 - Pack expansion in base specifier This adds support for the more general case, where the expansion pattern is not just...
Read more >
Many different kinds of revision specifiers - GNOME Blogs
When a new commit is made on a branch, the branch just records the new revision. Tags simply record a single revision, much...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found