Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Azure DevOps/VSTS always reports "DETACHED HEAD" on a clean repository

Friends,

I am now getting tired of Azure DevOps/VSTS. Jenkins was much better and still is, just my organization wants to use Azure DevOps.

I have a mystery which I need assistance to solve.

The following is the out of my repo from my laptop, it has no untracked or uncommitted changes.

git status
On branch master
Your branch is up to date with 'origin/master'.

nothing to commit, working tree clean

git remote -v
origin  https://github.com/xxx/terraformvsts.git (fetch)
origin  https://github.com/xxx/terraformvsts.git (push)

Guess, what, Azure Devops always complains that it has "DETACHED HEAD" , at every build execution.

Note the following from "Checkout" phase:

2019-02-05T05:55:33.2076875Z Note: checking out 'aad90fceecf39a7731c356ebfe2b547ddbce99e6'.
2019-02-05T05:55:33.2076992Z 
2019-02-05T05:55:33.2077872Z You are in 'detached HEAD' state. You can look around, make experimental
2019-02-05T05:55:33.2077939Z changes and commit them, and you can discard any commits you make in this
2019-02-05T05:55:33.2078179Z state without impacting any branches by performing another checkout.
2019-02-05T05:55:33.2078345Z 
2019-02-05T05:55:33.2078389Z If you want to create a new branch to retain commits you create, you may
2019-02-05T05:55:33.2078683Z do so (now or later) by using -b with the checkout command again. Example:
2019-02-05T05:55:33.2078717Z 
2019-02-05T05:55:33.2078933Z   git checkout -b <new-branch-name>
2019-02-05T05:55:33.2078966Z 
2019-02-05T05:55:33.2079004Z HEAD is now at aad90fc Clean Repository

The checkout phase for Build pipeline is like below:

enter image description here

How to resolve this issue? should I not do checkout? or one of the config settings in the Build pipelines should be amended?

like image 426
learner Avatar asked Feb 05 '19 06:02

learner


3 Answers

This is how Azure DevOps Pipelines is designed.

If you still need to checkout "that" branch (or any other specific branch), you can add a task:

- task: CmdLine@2
  displayName: Checkout $(Build.SourceBranchName)
  inputs:
    script: 'git checkout $(Build.SourceBranchName)'
like image 170
dan Avatar answered Sep 30 '22 19:09

dan


It's not complaining, this is how Azure DevOps works. I see on all builds, on all repos. nothing is wrong.

like image 28
4c74356b41 Avatar answered Sep 30 '22 21:09

4c74356b41


To checkout the source branch, run this step:

- script: |
    source=$(Build.SourceBranch)
    git checkout ${source#"refs/heads/"}

A solution with git name-rev --name-only $(Build.SourceBranch) did not work for me.

like image 33
armadill013 Avatar answered Sep 30 '22 20:09

armadill013