Pipeline database service is not ready

Hi,

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?

1 answer

1 accepted

0 vote

Hi Daniel,

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 :) 

Waiting for dependant services

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 :)

Wait until services are ready

Regards

Hi Nathan,

thank you for your answer. I will try the solution with the shell script and hope this functionality will be implemented someday in bitbucket pipelines.  :)

Regards,

Daniel

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

 

Suggest an answer

Log in or Join to answer
Community showcase
Piotr Plewa
Published Dec 27, 2017 in Bitbucket

Recipe: Deploying AWS Lambda functions with Bitbucket Pipelines

Bitbucket Pipelines helps me manage and automate a number of serverless deployments to AWS Lambda and this is how I do it. I'm building Node.js Lambda functions using node-lambda&nbsp...

717 views 0 4
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
Atlassian Team Tour

Join us on the Team Tour

We're bringing product updates and pro tips on teamwork to ten cities around the world.

Save your spot