Notice: This post is outdated. Please use the official post by GitLab.

Creating the .gitlab-ci.yml File

We will use Gitlab’s Docker build system to so we wont have to install Elixir ourselves. Create a .gitlab-ci.yml file with the following inside it:

image: elixir:1.3

Tells gitlab to use the Elixir dockerfile. Change the version number to suit your needs.

  - postgres:9.6

Imports the postgres service, change the version to suit your needs. If you don’t use postgres, you will have to swap this out with your respective DBMS.

  MIX_ENV: "test"

Ensure mix uses the testing environment.

  # Setup phoenix dependencies
  - apt-get update
  - apt-get install -y postgresql-client
  - mix local.hex --force
  - mix deps.get --only test
  - mix ecto.reset

Updates the system, and installs the postgres client (psql command) which is required by postgrex. Installs hex. Then gets the required dependencies and creates the test database and runs your migrations.

    - mix test

Runs your tests.

Updating the Config Settings

In config/test.exs, update the database hostname:

config :my_app, MyApp.Repo,
  hostname: if(System.get_env("CI"), do: "postgres", else: "localhost"),

This will set the hostname to postgres when the CI is running to be able to connect to the test database.

Add Migrations Folder

If you do not have any migrations, the migrations folder will be empty, and so it will not be added to git which means that Phoenix will throw an error. Go to priv/repo/migrations and create an empty file named .gitkeep if you do not have any migrations yet.