Home > Blockchain >  Is there any way to use a .env variable in a makefile?
Is there any way to use a .env variable in a makefile?

Time:11-29

I have a test pipeline that is set up in a docker container. Faux-environment variables are passed into the environment using a .env file.

In my .env file, I have this line:

MYSQL_ROOT_PASSWORD=dbpassword

In my Makefile, I have the following lines:

test-db:
    echo "create database dbname_test" | mysql -u root -h database -p${MYSQL_ROOT_PASSWORD}

This does not work, as I get the following output when running my test pipeline:

ERROR 2002 (HY000): Can't connect to MySQL server on 'database' (115) make: *** [Makefile:10: test-db] Error 1

Is there a way I can access the values in my .env file in my makefile?

CodePudding user response:

Maybe you should add a blank space between -p and ${MYSQL_ROOT_PASSWORD}

echo "create database dbname_test" | mysql -u root -h database -p ${MYSQL_ROOT_PASSWORD}
  • Related