how to redirect docker output to an artifact Edited

I'm running some tests (php-cs-fixer) inside a docker container as part of a bamboo build.

I can generate output in junit format, which I want to save as a build artifact and later process with bamboo's "JUnit Parser" task.

php-cs-fixer is not able to write to file, so I want to redirect stdout to a file, either inside the container or on the bamboo host.

I can do output redirection natively with docker, like so:

$ docker run my-docker-php-image sh -c 'vendor/bin/php-cs-fixer fix --format junit > /tmp/php-cs-fixer.xml'


Whilst typing up this question, I've got something to work. Perhaps this could be cleaned up and added to the bamboo documentation?

  1. create a docker task to "Run a docker container"
  2. set an image (mine is php + composer + required extensions from an internal docker repo)
  3. add volume for checked out code, eg ${}/deploy => /srv/app
  4. add volume for artifacts, eg ${}/artifacts => /srv/artifacts
  5. set working directory to /srv/app
  6. additional arguments: "--user root" (because I had an error writing to artifacts directory, possibly due to my container running as non-root, per security recommendations?)

The docker container command is then:

sh -c '"vendor/bin/php-cs-fixer" "fix" "--dry-run" "--config=.php_cs.dist" "--using-cache=no" "--format" "junit" > /srv/artifacts/php-cs-fixer.${bamboo.buildNumber}.xml'

You need to quote the hell out of everything, and also pass the whole command through "sh -c" so that output redirection works.

Lastly, add a "JUnit Parser" task, and make it final (since the tests will not always pass)

0 answers

Suggest an answer

Log in or Sign up to answer
How to earn badges on the Atlassian Community

How to earn badges on the Atlassian Community

Badges are a great way to show off community activity, whether you’re a newbie or a Champion.

Learn more
Community showcase
Published May 18, 2017 in Bamboo

FAQ: How to Upgrade Bamboo Server

Bamboo 5.9 will no longer be supported after June 12, 2017. What does this mean? As part of our End of Life policy, Atlassian supports major versions for two years after the first major iteratio...

1,786 views 0 6
Read article

Atlassian User Groups

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

Find a group

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

Find my local user group

Unfortunately there are no AUG chapters near you at the moment.

Start an AUG

You're one step closer to meeting fellow Atlassian users at your local meet up. Learn more about AUGs

Groups near you