1

I have a jenkins job with the following configurations as shown in the images,

SCM Configuration

Build Trigger

My workspace for jenkins is my local repo directory as given below D:\Jenkins\workspace\FirstProject\TestCI

ie TestCI is my github repo name which i cloned in the above location and set it as my jenkins workspace path.

so basically my jenkins job builds when a change is pushed to my github repo and after the build when i type git status in my local repo i get the error 'HEAD detached at '

What is the reason my head getting detached when jenkins job builds?

Flows
  • 3,040
  • 1
  • 19
  • 49

1 Answers1

3

I suspect that Jenkins checked out a particular commit, using it's commit ID. HEAD typically points to a branch, which points to a commit. e.g.

 cat HEAD
ref: refs/heads/master

Buf if you checkout the exact same commit using it's SHA then HEAD contains the SHA and you are in detached HEAD state.

git checkout bfe387b5fdcccdfb9d318b24589ab8f0eca9ab6a
Note: checking out 'bfe387b5fdcccdfb9d318b24589ab8f0eca9ab6a'.

You are in 'detached HEAD' state. You can look around, make experimental
changes and commit them, and you can discard any commits you make in this
state without impacting any branches by performing another checkout.

If you want to create a new branch to retain commits you create, you may
do so (now or later) by using -b with the checkout command again. Example:

  git checkout -b new_branch_name

HEAD is now at bfe387b... initial

Now if we look at HEAD we see that it contains the commit ID.

cat .git/HEAD
bfe387b5fdcccdfb9d318b24589ab8f0eca9ab6a
Randy Leberknight
  • 1,071
  • 7
  • 15