Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Gradle Environment variables. Load from file

I am new to Gradle.

Currently I have this task:

task fooTask {
    doLast {
        exec {
            environment 'FOO_KEY', '1234567' // Load from file here!
            commandLine 'fooScript.sh'
        }
    }
}

fooScript.sh

#!/bin/bash
echo $FOO_KEY

Everything works great. But I have env.file with all needed environment variables. This file is used in Docker builder.

env.file

FOO_KEY=1234567

Question: how can I use env.file together with Gradle environment to load all needed env. params?

like image 889
Justinas Avatar asked May 24 '18 12:05

Justinas


1 Answers

What about this :

task fooTask {
    doLast {
        exec {
            file('env.file').readLines().each() {
                def (key, value) = it.tokenize('=')
                environment key, value
            }
            commandLine 'fooScript.sh'
        }
    }
}
like image 113
ToYonos Avatar answered Oct 08 '22 08:10

ToYonos