Fork me on GitHub
#babashka
<
2021-06-04
>
maxp04:06:28

I'm trying to use bb tasks as Makefile replacement. How to import environment variables? like set -a ;; source .../myenv ;; ...

maxp05:06:34

now I do

:tasks
  {
    dev (shell "bash -c 'set -ae ; source VARS ; source ${DEV_ENV} && clojure -M:dev:nrepl'")
  }

maxp05:06:55

is there more elegant way?

mike_ananev05:06:58

@maxp Hi! In babashka I use the following method: 1. I can set and control any value by means of config files in EDN-format. I don't need ENV vars in most cases. See example https://github.com/redstarssystems/rssyslib/blob/4de3fa36fcf6fa629f4340bbefacd4842bddc606/bb.edn#L14 2. When I need to set ENV vars for subprocess I do it like this https://github.com/redstarssystems/rssyslib/blob/4de3fa36fcf6fa629f4340bbefacd4842bddc606/bb.edn#L46 3. To read ENV vars I use cprop function from-env

maxp05:06:01

cprop in Babashka - it's so good! ^)

maxp05:06:31

I prepare myself to switch from shell based scripts.

👍 3
borkdude07:06:27

@mike1452 you don't have to use env to pass environment variables to a child process, you can use (shell {:extra-env {"FOO" "BAR"}} ....)

👍 2
maxp07:06:34

That's what I need. is it documented?

maxp23:06:26

Could not find any "extra-env" in the hole page :(

borkdude07:06:42

It says it takes the same options as babashka.process/process :-)

👍 3
Adam Helins10:06:16

Can something similar be achieved before launching something with (clojure ...) ? (setting env vars)

borkdude10:06:40

exactly the same

Adam Helins10:06:47

Damn, I can't even find a single reason for complaining about BB

😆 2
Adam Helins11:06:02

By the way, I did write very simple caching for BB on CircleCI, it's not particularly smart but it works and allow for upgrading version: https://gist.github.com/helins/59e3abfc96f7a641d608a314fb6b8665

👍 2
borkdude11:06:48

what does the backslash before curl and tar mean?

Adam Helins11:06:06

Simply breaks the line, otherwise it was sometimes misbehaving in my terminal. But you could simplify it to something like this it seems: [ -f "bb.tar.gz" ] && tar -xzvf bb.tar.gz I forgot pretty much everything I knew about Bash...

borkdude11:06:58

kind of the point of bb