Getting elixir app version from command line

In some cases you need to know the version that is defined in your applications mixfile from the command line, maybe for an automated deployment process. No matter the case here is how you do it:

Create a mix task and place it at lib/mix/tasks/app/version.ex

defmodule Mix.Tasks.App.Version do
  use Mix.Task

  def run(_) do
    IO.puts Mix.Project.config[:version]
  end
end

Now you can easily get the current version by running mix app.version in your terminal.

Update:

If you don’t like the idea of adding a mix task for this or you cannot run mix in the environment you’re in I found this little command helpful:

cat mix.exs | grep version | sed -e 's/.*version: "\(.*\)",/\1/'

Happy coding!