mattmartian

mattmartian

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"
      }
    }
  }
}

Marked As Solved

stefanchrobot

stefanchrobot

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.

Also Liked

mattmartian

mattmartian

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!

Where Next?

Popular in Questions Top

Tee
can someone please explain to me how Enum.reduce works with maps
New
bsollish-terakeet
Credo is smart enough to check for (something like) this: assert length(the_list) == 0 with this response: Checking if an enum is empt...
New
albydarned
Hello all! I am typing this post from my new MacBook Pro with the M1 chip. I’m loving it so far, and will probably use it as my daily dr...
New
ycv005
I have followed this StackOverflow post to install the specific version of Erlang. And When I am running mix ecto.setup then getting fol...
New
New
Harrisonl
We have an ECS cluster with 4 services, where each task joins a single cluster, via discovery ECS discovery service. Currently when I de...
New
mcarvalho
What is the difference between System.get_env and Application.get_env? For example, what are best practices to use one versus another.
New
minhajuddin
I have seen a lot of code which picks the first element from a list using Enum.at(0) instead of List.first. Is there a reason why people ...
New
baxterw3b
Hi guys, i’m new in the Elixir world, and i have to say, that i love it! i’m having some problem to understand anonymous functions with ...
New
joeerl
Hello again - after a longish gap I’ve decided I really must dig into Elixir and see what’s been happening here - so I have a few questio...
New

Other popular topics Top

JDanielMartinez
Hi! May someone helps me, please! I have two apps into an umbrella project: the first one is Database, which manages queries, and the se...
New
peerreynders
Manning 2016 Halloween weekend sale via Deal of the Day Friday, October 28 - Half off all MEAPs - code WM102816LT Saturday, October 29 ...
326 29600 154
New
srinivasu
How to handle excepions in elixir? Suppose i have A, B, C ,D, E modules. and each module has get() function. A.get() method will call th...
New
grych
Hi folks, Few months ago I have announced the proof-of-concept of the library to manipulate the browsers DOM objects directly from Elixi...
639 49522 488
New
malloryerik
Hi, this is for people who, like me, have had some friction using .html.heex templates in VSCode. The solution seems to be, in a hyphena...
New
minhajuddin
I have seen a lot of code which picks the first element from a list using Enum.at(0) instead of List.first. Is there a reason why people ...
New
ashish173
I am using Ecto timestamps with postgres, I can see the timestamps() use the :naive_dateime but for my use case I wanted to store the ti...
New
alice
Hey, Just curious what are the main benefits of Elixir compared to Clojure? When is Elixir more useful than Clojure and vice versa? Th...
New
stefanluptak
Hello everybody, usually, I use a 29" ultra-wide monitor for VSCode which can easily accomodate explorer (files panel) + file with code ...
New
magnetic
Hey :wave:t3: Elixir community, I’ve been learning Elixir, and working on some side projects. My editor of choice is VSCode, and althoug...
New

We're in Beta

About us Mission Statement