Jenkins multibranch pipeline scan logs throwing git exception error — Possible scenarios

Rajath Hegde
3 min readJul 30, 2022
Jenkins multibranch scan logs for Bitbucket repository configuration

Hi folks,

I’m going to explain possible scenarios of Jenkins multibranch pipeline scan throwing git exception.

Below are the possible scenarios

Scenario 1: Invalid credentials

  1. You can check for configuration under pipeline configure section and select credentials drop-down.
  2. If you are not getting remote error and still scan logs are throwing error then go to Manage Jenkins > Manage Credentials.
  3. Select the credentials you want to update.
  4. Update the credentials and save it.
  5. Scan the logs, it should give success message.

Case study : Bitbucket credentials

Bitbucket cloud doesn’t allow external apps like Jenkins in this case to access repository even though username and password are valid. We need to use tokenized password to allow Jenkins to access bitbucket repository, username remains the same.

Below are the steps to generate tokenized password

  1. Login to Bitbucket.
  2. Go to User account > Settings > Personal settings.
  3. Under personal settings section, go to Access management > App password.
  4. Select add app password.
  5. You can use any label name and provide read access. After clicking on save, note the tokenized password and use this password in Jenkins where you have configured bitbucket credentials.
    PFB screenshot for creating tokenized password for reference.
Bitbucket add password

Scenario 2: Renaming existing feature branch and committing it to git creating confusion in git working tree to re-index during scan

In this scenario, we have committed our changes to feature branch i.e. feature1 and requirement comes in to rename existing feature branch i.e. develop and this new branch will be committed to repository. When we scan the logs, we get git exception even though multibranch pipeline configurations are configured properly. In this case, we need to clear git cache residing in Jenkins home path.

Below are the steps to be followed to clear git cache

  1. Go to Jenkins home directory cache folder.
    If you are not sure about jenkins home path you can check in Manage Jenkins > Configure System > Home directory
    Windows : C:\Users\username\.jenkins\caches
    Linux : /var/lib/jenkins/.jenkins/caches
  2. For Windows, use git bash, it will be easier.
  3. List all the git cached folders and sort them according to recent ones
    ls -lrt
  4. Go to the recent git-commithash folder and list the hidden .git directory
    ls -la
  5. If .git folder is not present, check the previous recent git-commithash folders, it’s all trial and error basis.
  6. Once you find .git folder, use the below command to check git repository name
    git config --get remote.origin.url
  7. The above command URL should match with multibranch pipeline scan log git URL.
  8. If both URL’s are same, delete .git folder in caches folder and re-scan multibranch pipeline. It should give success message and new feature branch gets updated.
    Note: If you are curious to check if git is building new revision tree, go to same git-commithash folder where you deleted .git folder, it will create new .git folder, use the below command
    git ls-remote -h $(git config --get remote.origin.url) | cut -c53-
    You can find the new feature branch in the list.

I hope you find this case study helpful.
Happy coding! :)

--

--