Conditions in Bitbucket Pipelines

6/3/2019

I'm setting up Continuous Deployment for an application that is to be deployed to a Kubernetes Engine and there are a number of commands that I would like to run only if they either aren't installed or don't need to be ran on the 2nd instance.

I don't want to have any assumptions or pre-CD requirements, such as "kubectl must already be installed", "Cluster must already exist" or "Container already exists with the image deployed".

I basically want checks in my bitbucket pipelines to check whether I need to call either of the following depending whether the container exists in the first place:

kubectl run my-container --image=$IMAGE_NAME

or

kubectl set image deployment/my-container my-container=$IMAGE_NAME

Having something like this allows me to be completely flexible with my setup, so if the cluster hasn't been setup or kubectl isn't installed for example, then the deployment will go ahead and set it up and install it.

My experience is with Team City working with Octopus and they have a lovely interface where these checks can be made. Is it best in Bitbucket Pipelines to call a custom script, then I would write it all? I just think it would be so much nicer in the script section itself, so if it fails it's easier to find out why.

What would be the best way to achieve this?

-- Lloyd Powell
bitbucket-pipelines
continuous-deployment
kubernetes

0 Answers