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.
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--
Hi Eduardo, thanks for the quick response. Can I use this script in Windows too or do I need to make some modifications?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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--
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.