When circle ci checkouts out code it's dropping the branch

Hi there.
I have a build that used to work just fine. in recent weeks i’ve noticed some points of failure. one specifically is this. In the checkout code block i get this message. I see that maybe I should add git to my docker container so i’ve started that process!

Either git or ssh (required by git to clone through SSH) is not installed in the image. Falling back to CircleCI's native git client but the behavior may be different from official git. If this is an issue, please use an image that has official git and ssh installed.
Enumerating objects: 502, done.
Counting objects: 100% (502/502), done.
Compressing objects: 100% (341/341), done.
Total 27060 (delta 336), reused 294 (delta 156), pack-reused 26558

however here is what is odd. The repo clones but it clones with the commit and no branch associated with it. When i ssh into the build i can see

* (no branch)
  main

yet the build is clearly on a branch when you look at the circle ci interface. Has anyone else seen this behavior? many thanks for any insight. it doesn’t seem like updating git would fix a “missing” branch.

Hi @lwasser! Welcome to our CircleCI community!

For this build where you are seeing this error, are you using a custom image? I do remember seeing this error a few times in the past few weeks when users were utilizing a custom image.

If you could share a code snippet of your job, that would be helpful. If you are not comfortable doing that here, please do submit a support ticket here, mention this Discuss post, and I can investigate further! Thanks!

1 Like

Hi @jonathanc503 I am totally happy to share my workflow. it’s a private repo but it is ONLY private because we save answers to student code assignments in it (we publish the output plots and such but hide the code). Anyone is welcome to see our build.

Here is the top part. i could include the rest but this is the part that actually sets up the repository (earth-analytics-lessons) in the earthlab organization. Note that in the second run statement i grab the branch name being processed and write it to a text file to use later. i have it printed out as well just as a sanity check given what was happening!

So i did go ahead and update our docker container so it installed git and ssh. And that issue went away immediately. it surprised me because i would think the code checkout part would be somewhat standard but perhaps it isn’t?

So if anyone reads this - the fix was to simply install git and ssh (i may not have needed the ssh part but i did just in case).

version: 2
jobs:
  build:
    working_directory: ~/earth-analytics-lessons
    docker:
      - image: earthlab/r-python-eds-lessons-env:latest

    steps:
      - checkout
      - run:
          name: Check conda environment
          command: |
            conda env list
            conda list
      - run:
          name: Get current branch
          working_directory: ~/earth-analytics-lessons
          command: |
            echo $(git rev-parse --abbrev-ref HEAD) > current_branch.txt
            cat current_branch.txt

Hi @lwasser - Thank you for the update here! I was just circling back (pun intended) to comment on this thread again. I was able to confirm the only cases we’ve seen of this occurring was with a custom image where git AND ssh are not installed. So you were correct to add both packages to your custom image here. (This is also the reason all CircleCI convenience images have these packages installed by default.)

If you only installed git, you may have still encountered the “git is not installed” error message. The reason is because CircleCI performs the checkout code with ssh protocol.

I’m glad your build is up and running again! Happy building!

1 Like

Hi there @JonathanC503 :wave: thank you for this! I took that approach to fix things hoping it might do the trick. Now that i understand checkout uses SSH it makes a lot more sense that things weren’t behaving as expected! What was odd is that it happened after a few years or working well. BUT perhaps this also has to do with some changes that GitHub is making + circleCi backend changes?

Anyway our builds are happily processing again and I can update our online lessons again so thank you for the help and speedy replies here!

1 Like

This topic was automatically closed 10 days after the last reply. New replies are no longer allowed.