I've encountered a issue using a database service and running my unit tests. The tests started before the database service was ready and due this the unit tests failed.
Has anybody else had similar behaviors?
There are a number of ways you can wait for a service to be ready before executing your test command in pipelines but it all depends on how your service is determined to be ready.
This question from the community has a bash script that awaits mariadb/mysql to be ready by testing if a TCP connection can be established to the databases port, you can tweak this port for your service aswell if its not one of those databases :)
Whilst that script may work for databases it only awaits it to be ready for connections if you also require waiting for schema changes or data imports you will have to write your own custom bash scripts for this behaviour but the logic will be much the same poll checking (waiting) for the condition you are after.
Also feel free in the meantime to watch the following open feature request for this to be added to pipelines :)
hope this functionality will be implemented someday in bitbucket pipelines. :)
Until Docker implements a standard event in which all containers can notify interested parties that they are truly ready (and every image honours it), Bitbucket Pipelines won't be able to wait for databases to be ready in any sort of standard way.
You'll need to health-check in a loop, e.g.
until docker run --rm --link my_db_container:pg --net my_db_network postgres pg_isready -U postgres -h pg > /dev/null 2>&1; do sleep 1; done
We’ve been building a plugin to integrate Bitbucket Server and Jenkins CI, and I’m excited to announce that our alpha is ready to download and install. It lets you seamlessly configure a Jenkins job ...
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