Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

Bamboo detached HEAD

Peter Drexel March 6, 2024

Regarding the detached HEAD message that sometimes appears in the Bamboo build logs, is there a configuration option that will trigger a failure of the build when this occurs or is there a way to detect that this has occurred so that we know the build is not legit? For the latter, I'm thinking about programmatically "looking" at the build log, "seeing" detached HEAD message and forcing a failure.

1 answer

3 votes
Eduardo Alvarenga
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
March 6, 2024

Hello @Peter Drexel,

Bamboo will not fail the build in case of a detached HEAD because whenever you rerun a build that is based on a commit revision that is not the HEAD any longer, it should continue normally.

In your case, if you'd like to avoid that you can add a script task that will check if the current checked-out tree is not in a HEAD state and fail it if so. For example:

#!/bin/bash

# Check if we are in a git repository
if git rev-parse --git-dir > /dev/null 2>&1; then
# Check if HEAD is detached
if git status | grep -q 'HEAD detached'; then
echo "ERROR: The current checked out code is in a detached HEAD state."
exit 127
else
echo "HEAD is attached. All is good."
fi
else
echo "This is not a Git repository."
fi

By adding the steps above after the checkout task, Bamboo will validate if the checked out code is in a HEAD state and exit with a "127" error code in case it is. You can pick the error code you want.

Thank you,

 

Eduardo Alvarenga
Atlassian Support APAC

--please don't forget to Accept the answer if the reply is helpful-- 

Peter Drexel March 7, 2024

Hi Eduardo, thanks for the quick response. Can I use this script in Windows too or do I need to make some modifications?

Eduardo Alvarenga
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
March 7, 2024

Hi @Peter Drexel

You can certainly run in Windows If the Agent has some type of runtime engine such as Cygwin to interpret the bash script. Some recent versions of Windows will support bash natively.

Otherwise, I suggest you migrate the logic to Powershell or Windows Batch language.

Thank you,

Eduardo Alvarenga

Atlassian Support APAC

--please don't forget to Accept the answer if the reply is helpful-- 

Like Ayrijit Swain likes this

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events