Woodsman
Woodsman

Reputation: 1179

Jenkins says it can't find Git branch, but it clearly exists

I created a new pipeline for testing purposes to build a feature branch.

Git branch: feature/show-percentage-of-completion Script path: Jenkinsfile-cirrus-dev-feature Lightweight checkout: Not checked

When I run the build, I get this error below:

    Started by user [email protected]
    Checking out git [email protected]:IC2E-SPRINT/cirrus-bluecost-ssc-file-generator.git into /jenkins_data/jenkins_home/jobs/cirrus-bluecost-ssc-cost-file-generator-dev-feature/workspace@script to read Jenkinsfile-cirrus-dev-feature
    The recommended git tool is: git
    using credential bluecost_git
     > git rev-parse --resolve-git-dir /jenkins_data/jenkins_home/jobs/cirrus-bluecost-ssc-cost-file-generator-dev-feature/workspace@script/.git # timeout=10
    Fetching changes from the remote Git repository
     > git config remote.origin.url [email protected]:IC2E-SPRINT/cirrus-bluecost-ssc-file-generator.git # timeout=10
    Fetching upstream changes from [email protected]:IC2E-SPRINT/cirrus-bluecost-ssc-file-generator.git
     > git --version # timeout=10
     > git --version # 'git version 2.20.1'
    using GIT_SSH to set credentials Bluecost (dpydalsprd101.sl.bluecloud.mycompany.com, /home/bluecost/.ssh )
     > git fetch --tags --force --progress -- [email protected]:IC2E-SPRINT/cirrus-bluecost-ssc-file-generator.git +refs/heads/*:refs/remotes/origin/* # timeout=10
     > git rev-parse refs/remotes/origin/feature/show-percentage-of-completion^{commit} # timeout=10
     > git rev-parse origin/feature/show-percentage-of-completion^{commit} # timeout=10
    ERROR: Couldn't find any revision to build. Verify the repository and branch configuration for this job.
    ERROR: Maximum checkout retry attempts reached, aborting
    Finished: FAILURE

What I don't understand about Jenkins is that I give it a repo and a branch name. Does it do git clone my-repo and then git checkout my-branch? No, it have to do this weird git --version, git --version ; git fetch; git rev-parse; git rev-parse. I have no idea why they found a set of cryptic steps to do this.

Also, I've verified both the repository and the branch exist. If I switched to the test branch, it would work. Why?

PS: a comment was made about checking the ref/spec. I wasn't sure where the commenter was referring, but I noticed this exists in the .git/config file as follows:

[branch "feature/show-percentage-of-completion"]
    remote = origin
    merge = refs/heads/feature/show-percentage-of-completion

enter image description here

Upvotes: 3

Views: 7613

Answers (1)

VonC
VonC

Reputation: 1324515

Check your refspec, as seen here.
It should be, in order to fetch all the remote tracking braches, including origin/feature/xxx:

+refs/heads/*:refs/remotes/origin/*

Note:

The Git plugin fetches branches and then look for the HEAD commit to checkout, which means it puts the repository in a detached HEAD state: it switch to a commit, not a branch itself.
Maybe that commit was laready part of a previous build.

As commented below by iftimie-tudor, try and tweak the branch field:

feature/show-percentage-of-completion 
# or
*/show-percentage-of-completion

Upvotes: 1

Related Questions