# First time setting up CI/CD on BitBucket

**URL:** <https://discourse.julialang.org/t/first-time-setting-up-ci-cd-on-bitbucket/68526>\
**Category:** Tooling\
**Created:** [September 21, 2021, 1:42pm UTC](https://discourse.julialang.org/t/first-time-setting-up-ci-cd-on-bitbucket/68526 "2021-09-21T13:42:17Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![affans](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/affans/32/11911_2.png) [@affans](https://discourse.julialang.org/u/affans)\
**Post date:** [September 21, 2021, 1:42pm UTC](https://discourse.julialang.org/t/first-time-setting-up-ci-cd-on-bitbucket/68526/1 "2021-09-21T13:42:17Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![SamRodkey](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/samrodkey/32/26068_2.png) [@SamRodkey](https://discourse.julialang.org/u/SamRodkey)\
**Post date:** [September 21, 2021, 9:59pm UTC](https://discourse.julialang.org/t/first-time-setting-up-ci-cd-on-bitbucket/68526/2 "2021-09-21T21:59:49Z")

</div>

Hello!

Not sure if you’ve structured your code as a package, because [if so this will pretty easy](https://pkgdocs.julialang.org/v1/managing-packages/#Testing-packages).

# 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-auto
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-auto
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.

---

<div class="post-metadata">

**Author:** ![affans](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/affans/32/11911_2.png) [@affans](https://discourse.julialang.org/u/affans)\
**Post date:** [September 22, 2021, 12:58pm UTC](https://discourse.julialang.org/t/first-time-setting-up-ci-cd-on-bitbucket/68526/3 "2021-09-22T12:58:41Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![affans](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/affans/32/11911_2.png) [@affans](https://discourse.julialang.org/u/affans)\
**Post date:** [September 22, 2021, 1:52pm UTC](https://discourse.julialang.org/t/first-time-setting-up-ci-cd-on-bitbucket/68526/4 "2021-09-22T13:52:11Z")

</div>

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"])`

---

<div class="post-metadata">

**Author:** ![SamRodkey](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/samrodkey/32/26068_2.png) [@SamRodkey](https://discourse.julialang.org/u/SamRodkey)\
**Post date:** [September 22, 2021, 2:21pm UTC](https://discourse.julialang.org/t/first-time-setting-up-ci-cd-on-bitbucket/68526/5 "2021-09-22T14:21:03Z")

</div>

The easiest way to do this that I know of is to activate the environment for your project, and then [use the `instantiate` command](https://pkgdocs.julialang.org/v1.1/environments/#Using-someone-else's-project-1), to make sure all the dependencies are installed in one batch.

To do this in one line might be something like:

```julia
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](https://pkgdocs.julialang.org/v1.1/api/#Pkg.instantiate).

---

<div class="post-metadata">

**Author:** ![affans](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/affans/32/11911_2.png) [@affans](https://discourse.julialang.org/u/affans)\
**Post date:** [September 22, 2021, 5:32pm UTC](https://discourse.julialang.org/t/first-time-setting-up-ci-cd-on-bitbucket/68526/6 "2021-09-22T17:32:00Z")

</div>

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

```julia
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

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

```

but running it does nothing?

```julia
➜ 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)

---

<div class="post-metadata">

**Author:** ![SamRodkey](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/samrodkey/32/26068_2.png) [@SamRodkey](https://discourse.julialang.org/u/SamRodkey)\
**Post date:** [September 23, 2021, 5:25pm UTC](https://discourse.julialang.org/t/first-time-setting-up-ci-cd-on-bitbucket/68526/7 "2021-09-23T17:25:01Z")

</div>

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.
