I have two branches on BitBucket: master
and develop
. I\'ve also got a BitBucket Team Folder job configured on my Jenkins server to build that reposito
I could not get the two answers above to work. I was triggering a Jenkins pipeline job by specifying a branch and was trying to checkout another branch (develop) in the job which was failing with:
error: pathspec 'develop' did not match any file(s) known to git.
I could see this in the failing job, which indicated that only the triggering branch was being fetched:
git fetch --no-tags --progress https:// +refs/heads/branch-name:refs/remotes/origin/branch-name
I got it to work by changing the remote fetch config and fetching all branches by doing the following after doing just the default checkout scm
step in the triggered job's Jenkinsfile:
sh """
git config remote.origin.fetch '+refs/heads/*:refs/remotes/origin/*'
git fetch --all
"""
This is thanks to this answer https://stackoverflow.com/a/39986737/1988883
This also avoids having to configure Jenkins for GitSCM script approvals which I had to do for trying out the two solutions above