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

It's not the same without you

Join the community to find out what other Atlassian users are discussing, debating and creating.

Atlassian Community Hero Image Collage

git issue using atlassian/bamboo-agent-base docker image Edited

My goal is to run some git command inside a build using Bamboo YAML spec and atlassian/bamboo-agent-base docker image.

This is the Dockerfile extended from atlassian/bamboo-agent-base (copied from https://hub.docker.com/r/atlassian/bamboo-agent-base)

FROM atlassian/bamboo-agent-base
USER root
RUN apt-get update && \
apt-get install maven -y && \
apt-get install git -y

The image is built as 

atlassian-bamboo-extended:latest

Here is my bamboo yaml spec:

project:
key: COM
plan:
key: CSP
name: project CI
dockerImage: atlassian-bamboo-extended:latest
stages:
- jobs:
- scripts:
- '#!/bin/bash'
- echo starting push code task
- ls -la
- pwd
- git status
- git diff
- echo finished push code task
interpreter: shell




 

 

When the job runs, "ls -la" does list the source code. Here is the output of the rest of the command:

13-Feb-2019 23:22:29 error: object directory /var/bamboo/xml-data/build-dir/_git-repositories-cache/99b53e1f0d967effa88f7452e5067096c9acf7e1/.git/objects does not exist; check .git/objects/info/alternates.
13-Feb-2019 23:22:29 fatal: bad object HEAD

When the build is run without using the docker image, it works fine:

13-Feb-2019 23:25:07 On branch feature/SE-1234
13-Feb-2019 23:25:07 Your branch is up-to-date with 'origin/feature/SE-1234.
13-Feb-2019 23:25:07
13-Feb-2019 23:25:07 nothing to commit, working directory clean

Is there any reason why git does not work in the docker image?

 

3 answers

It appears that when bamboo clones the source repository it leverages "git alternate objects" (presumably to be space efficient).

As a result, the cloned repository contains references to objects that exist outside of $PWD - it your case it's:

/var/bamboo/xml-data/build-dir/_git-repositories-cache/99b53e1f0d967effa88f7452e5067096c9acf7e1/.git/objects

if you attempt to perform git operations from within the container you end up with an error log full of:

 error: refs/XXXX does not point to a valid object!

because that directory won't exist inside of the container unless you've explicitly mounted it.

The workaround is thus to either mount the cache directory into your container 🤮 (read only!) or add a shell task that "dissociates" your clone so there are no references to external objects. I used:

git repack -a -d

and that seems to have resolved the problem.

0 votes
Marty Atlassian Team Feb 14, 2019

Hi Dennis,

I am not an expert on Docker or git, but I will see if I can help.

How does the source code get into the container?

I didn't see any COPY command in your Dockerfile.

Also it looks like the .git folder is missing from the container https://medium.freecodecamp.org/understanding-git-for-real-by-exploring-the-git-directory-1e079c15b807

Also just wondering why you want to do a status and a diff inside a container, what is the higher level task you are trying to achieve?  There may be an alternative way to do what you're trying to do.

I want to increment pom version and auto-commit to stash. Before I can do that, even git status does not work. The .git folder is there.

The source code is automatically put inside the docker container when I have dockerImage: in the bamboo yaml spec.

When I cat the config file in .git, the remote origin is set to some cache file outside of the container instead of the original url. 

After I run these commands, it works:

git remote set-url https://<stash url>

git pull

Just wonder how using 

dockerImage:

in the bamboo yaml spec would change the git head.

Like Marty likes this
Marty Atlassian Team Feb 15, 2019

It's not that the git head is "changed", it's that most of the setup in Docker container is already done in atlassian/bamboo-agent-base.

I was using "FROM atlassian/bamboo-agent-base" and it does not have git pre-install in it.

I was able to get around this by turning off repository caching in the build configuration. Not ideal, true, but it seems to fix the issues and not require additional git commands.

Suggest an answer

Log in or Sign up to answer
TAGS
Community showcase
Published in Bamboo

Bamboo 7.1 is here and is packed with value!

I'm happy to announce that Bamboo 7.1 has been released and it’s overflowing with awesome new features. Top-voted issues First and foremost, a bunch of JAC top voted issues has been delivered - y...

621 views 1 6
Read article

Community Events

Connect with like-minded Atlassian users at free events near you!

Find an event

Connect with like-minded Atlassian users at free events near you!

Unfortunately there are no Community Events near you at the moment.

Host an event

You're one step closer to meeting fellow Atlassian users at your local event. Learn more about Community Events

Events near you