Skip to content

Commit fc91307

Browse files
committed
Implement environment vars for executions
1 parent bc9543b commit fc91307

File tree

4 files changed

+16
-4
lines changed

4 files changed

+16
-4
lines changed

sync/config.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,11 @@ type DatabaseOptions struct {
3131
Mysql string
3232
}
3333

34+
type EnvironmentVar struct {
35+
Name string
36+
Value string
37+
}
38+
3439
type Database struct {
3540
Type string
3641
Schema string
@@ -64,6 +69,7 @@ type Execution struct {
6469
Type string
6570
Command YamlStringArray
6671
Workdir string
72+
Environment []EnvironmentVar
6773
Options struct {
6874
}
6975
}

sync/database.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import (
99

1010
func (database *Database) ApplyDefaults(server *Server) {
1111
// set default connection if not set
12-
if (commandbuilder.Connection{}) == database.Connection {
12+
if database.Connection.IsEmpty() {
1313
database.Connection = server.Connection
1414
}
1515
}

sync/execution.go

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,13 +35,20 @@ func (execution *Execution) commandBuilder(server *Server) []interface{} {
3535
case "local":
3636
connection = commandbuilder.Connection{Type:"local"}
3737
case "remote":
38-
connection = server.Connection
38+
connection = server.Connection.Clone()
3939
}
4040

41+
// set working directory
4142
if execution.Workdir != "" {
4243
connection.WorkDir = execution.Workdir
4344
}
4445

46+
// set environment
47+
connection.Environment = map[string]string{}
48+
for _, val := range execution.Environment {
49+
connection.Environment[val.Name] = val.Value
50+
}
51+
4552
if len(execution.Command.Multi) >= 1 {
4653
// multi element command (use safer quoting)
4754
return connection.ShellCommandBuilder(execution.Command.Multi...)

sync/filesystem.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,11 @@ package sync
33
import (
44
"fmt"
55
"strings"
6-
"github.com/webdevops/go-shell/commandbuilder"
76
)
87

98
func (filesystem *Filesystem) ApplyDefaults(server *Server) {
109
// set default connection if not set
11-
if (commandbuilder.Connection{}) == filesystem.Connection {
10+
if filesystem.Connection.IsEmpty() {
1211
filesystem.Connection = server.Connection
1312
}
1413

0 commit comments

Comments
 (0)