First time setting up CI/CD on BitBucket

Looking for some assistance in setting up CI/CD on Bitbucket pipeline. I have a package with a test folder that includes all my unit tests. How can I make it so that everytime I commit code, it runs all the tests?


Not sure if you’ve structured your code as a package, because if so this will pretty easy.

If Code Structured as a Package

Basically, you need to just need to add a shell script or instructions in your Bamboo task definition which calls Julia and runs the tests for your package. This presumes you’re running from inside a Docker container or on a machine with Julia installed.

For a fictional package named “PlotMagic” the simplest way to accomplish this is to use the following command line call from the root of the package directory:

julia --project -e 'using Pkg; Pkg.test("PlotMagic")'

This command is doing several things:

  • Calling julia
  • The --project flag is saying “use the environment in the current working directory”, which is presumably the environment specification for your package where you specify all the dependencies.
  • the -e flag is saying “execute the following expression”, where we activate the Package manager Pkg and tell it to run the tests for our package PlotMagic.

If you want to get fancy, you could also call the command to update and install the project dependencies before you test, so you’re always always working with the newest version of those.

Code Not Structured as a Package

If you have a fictional magic_plot_test_entry_point.jl file which has all your tests, just pass the path to the file as an argument of the julia executable as follows:

julia .\src\magic_testing_folder\magic_plot_test_entry_point.jl

Doing either of these commands should be pretty trivial if you have Bamboo setup for CI with your Bitbucket installation.

Thanks, this is very helpful. I will give this a shot!

So my code is a package, and I am able to run the commands like you described. However, my question is that is there a way to install the packages automatically from the Project/Manifest file instead of manually typing in Pkg.add(["pkgA", "pkgB"])

The easiest way to do this that I know of is to activate the environment for your project, and then use the instantiate command, to make sure all the dependencies are installed in one batch.

To do this in one line might be something like:

julia --project -e 'using Pkg; Pkg.instantiate()'

I believe this command will basically install everything in your package Project.toml file and their dependencies in one call.

Great, very helpful. So now I have a docker file in my directory that looks like

FROM julia:latest

RUN useradd --create-home juliauser
WORKDIR /home/juliauser
COPY . .
RUN chmod 700 install.jl
#USER juliauser # don't login as user since permission issues
#RUN julia --project install.jl
RUN julia -e '1 + 1'

here I am just trying to run a simple 1 + 1 expression. This docker builds successfully

➜  counterfactuals git:(master) ✗ docker build -t covid19abm_docker .
[+] Building 0.8s (11/11) FINISHED     

but running it does nothing?

➜  counterfactuals git:(master) ✗ docker run covid19abm_docker       
➜  counterfactuals git:(master) ✗ 

i.e no output… is it because I am using RUN commands and not CMD commands?

Ultimately, I’d like to run my install.jl file (which has the code to execute my unit tests) upon commiting code to a bitbucket repo. (I am even confused on how will bitbucket even parse the test results)

I know that if you use the built-in Test package in Julia, when you get a failed test, julia will exit with a return a non-zero exit code, which is usually interpreted by Bamboo as a failure. Passing tests will usually result in a zero exit code.

Usually I just look at the logs from a particular build/test attempt and they are useful enough to debug which test fails. If you have a custom tests script, that may be harder to parse if you’re not writing stuff to standard output.