10

Folks, There is an environment variable a job is configured with, BRANCH, but when I try configuring git scm with it, i get an error in console

Branch Specifier (blank for 'any') */${BRANCH}

git rev-parse refs/remotes/origin/${BRANCH}^{commit} # timeout=10 git rev-parse refs/remotes/origin/origin/${BRANCH}^{commit} # timeout=10 git rev-parse origin/${BRANCH}^{commit} # timeout=10 ERROR: Couldn't find any revision to build.

I am 100% certain git is fine, branch exists.

Cmag
  • 14,946
  • 25
  • 89
  • 140

2 Answers2

23

So under full checkout , Change */${BRANCH} to */$BRANCH, this should read the environment variable.

Branch Specifier (blank for 'any') */$BRANCH

In Pipelines, make sure you aren't specifying a Lightweight Checkout. As of Jenkins 2.73, Lightweight Checkouts will not read the environment variable, but a full checkout will

Check this issue discussion for more details https://github.com/jenkinsci/ghprb-plugin/issues/564

Aarish Ramesh
  • 6,745
  • 15
  • 60
  • 105
  • 6
    Yes, I think untick `Lightweight Checkout` fix the problem. Thanks. – River2202 Feb 27 '20 at 21:39
  • I was able to keep the curly brackets `${BRANCH}`. The fix for me was indeed to uncheck `Lightweight Checkout` – HokiEJP Aug 31 '21 at 19:21
  • This is not working for me : `> git.exe rev-parse "refs/remotes/origin/$BRANCH^{commit}" # timeout=10 > git.exe rev-parse "origin/$BRANCH^{commit}" # timeout=10 ERROR: Couldn't find any revision to build. Verify the repository and branch configuration for this job.` I'm using BitBucket and don't have an option for 'lightweight checkout' – Symo Mar 14 '22 at 15:45
  • @SimonStorr keep the curly brackets, i.e., use ${BRANCH} not $BRANCH. Not sure why some answers are saying get rid of those. – Chris Wong May 06 '22 at 22:46
2

Change */${BRANCH} to */$BRANCH, this works for me.

Branch Specifier (blank for 'any') */$BRANCH

mainframer
  • 20,411
  • 12
  • 49
  • 68
  • 1
    @chrmod were you using pipelines, or just plain-old Jenkins? I got the same issue as you today, but only when using pipelines. – thiagowfx May 03 '17 at 03:42
  • @thiagowfx I think this issue is resolved in Pipelines these days. You can try to update pipeline plugins. – chrmod May 03 '17 at 07:49
  • 15
    In Pipelines, make sure you aren't specifying a Lightweight Checkout. As of Jenkins 2.73, Lightweight Checkouts will not read the environment variable, but a full checkout will. – Chad Gilbert Oct 30 '17 at 11:46