inject ssh env vars by apppending them to the script
Some checks failed
ci/woodpecker/push/go-lint Pipeline failed
Some checks failed
ci/woodpecker/push/go-lint Pipeline failed
This commit is contained in:
@@ -471,9 +471,6 @@ func (command *Command) RunCmdOnHost(cmdCtxLogger zerolog.Logger, opts *ConfigOp
|
||||
}
|
||||
defer commandSession.Close()
|
||||
|
||||
// Inject environment variables
|
||||
injectEnvIntoSSH(envVars, commandSession, opts, cmdCtxLogger)
|
||||
|
||||
// Set output writers
|
||||
cmdOutWriters = io.MultiWriter(&cmdOutBuf)
|
||||
if IsCmdStdOutEnabled() {
|
||||
@@ -492,6 +489,7 @@ func (command *Command) RunCmdOnHost(cmdCtxLogger zerolog.Logger, opts *ConfigOp
|
||||
return command.runScriptFile(commandSession, cmdCtxLogger, &cmdOutBuf)
|
||||
case PackageCommandType:
|
||||
var remoteHostPackageExecutor RemoteHostPackageExecutor
|
||||
injectEnvIntoSSH(envVars, commandSession, opts, cmdCtxLogger)
|
||||
return remoteHostPackageExecutor.RunCmdOnHost(command, commandSession, cmdCtxLogger, cmdOutBuf)
|
||||
default:
|
||||
if command.Shell != "" {
|
||||
@@ -501,6 +499,12 @@ func (command *Command) RunCmdOnHost(cmdCtxLogger zerolog.Logger, opts *ConfigOp
|
||||
}
|
||||
cmdCtxLogger.Debug().Str("cmd + args", ArgsStr).Send()
|
||||
|
||||
//! environment vars and SSH:
|
||||
//? skip if commandType is not *script*?
|
||||
//? option to use SSH setenv or add to beginning?
|
||||
// Inject environment variables
|
||||
injectEnvIntoSSH(envVars, commandSession, opts, cmdCtxLogger)
|
||||
|
||||
if command.Type == UserCommandType && command.UserOperation == "password" {
|
||||
// cmdCtxLogger.Debug().Msgf("adding stdin")
|
||||
|
||||
@@ -673,6 +677,11 @@ func (command *Command) runScriptFile(session *ssh.Session, cmdCtxLogger zerolog
|
||||
func (command *Command) prepareScriptBuffer() (*bytes.Buffer, error) {
|
||||
var buffer bytes.Buffer
|
||||
|
||||
for _, envVar := range command.Environment {
|
||||
buffer.WriteString(fmt.Sprintf("export %s", envVar))
|
||||
buffer.WriteByte('\n')
|
||||
}
|
||||
|
||||
if command.ScriptEnvFile != "" {
|
||||
envBuffer, err := readFileToBuffer(command.ScriptEnvFile)
|
||||
if err != nil {
|
||||
@@ -694,6 +703,11 @@ func (command *Command) prepareScriptBuffer() (*bytes.Buffer, error) {
|
||||
func (command *Command) prepareScriptFileBuffer() (*bytes.Buffer, error) {
|
||||
var buffer bytes.Buffer
|
||||
|
||||
for _, envVar := range command.Environment {
|
||||
buffer.WriteString(fmt.Sprintf("export %s", envVar))
|
||||
buffer.WriteByte('\n')
|
||||
}
|
||||
|
||||
// Handle script environment file
|
||||
if command.ScriptEnvFile != "" {
|
||||
envBuffer, err := readFileToBuffer(command.ScriptEnvFile)
|
||||
|
||||
Reference in New Issue
Block a user