Jenkins: mix: command not found on jenkins file

Im trying to get my jenkins job to run tests, however im having a hard time getting it to work and recognize the command, is there a better way to do this? i want the pipeline to fail if all of the tests dont pass and eventually build it into a docker image to send off to an eks. If any more info is needed please let me know!

Jenkinsfile

pipeline {
  agent any

  stages {
    stage("Build") {
      steps {
        sh "MIX_ENV=test mix do deps.get, deps.compile"
      }
    }

    stage("Test") {
      steps {
        sh "MIX_ENV=test mix test"
      }
    }
  }
}

Looks like Elixir is not installed in the environment where you’re trying to invoke the mix command. Hard to say what’s happening without more context.

But I’d suggest running your test with Docker and Docker Compose so that you can reproduce it locally. Something like this would work:
test/docker-compose.yml:

version: '3'

services:
  db:
    image: postgres:11.12
    environment:
      POSTGRES_PASSWORD: postgres
      POSTGRES_DB: myapp_test

  myapp:
    build:
      context: ../
      dockerfile: test/Dockerfile
    depends_on:
      - db

test/Dockerfile:

FROM hexpm/elixir:1.10.3-erlang-23.3.4-alpine-3.12.0

RUN apk add --update --no-cache build-base

# prepare build dir
WORKDIR /app

RUN mix local.hex --force && \
    mix local.rebar --force
COPY . .
RUN mix do deps.get

ENV MIX_ENV=test
RUN mix compile

CMD mix test

and then run it from CI:

docker-compose -f test/docker-compose.yml build
docker-compose -f test/docker-compose.yml up -d
docker-compose -f test/docker-compose.yml run --rm myapp
docker-compose -f test/docker-compose.yml down

I’d then have a separate Dockerfile for building the release image.

Awesome, thank you so much for the info! and for more context, to start to learn how to get my elixir into jenkins i made an example app and was hooking it up to get it to try and run the unit tests in the test folder, and then if they pass build an image to send off to EKS. This helps a lot i really appreciate it!

1 Like