Skip to content

Commit

Permalink
wip(ci): add env path to shell class
Browse files Browse the repository at this point in the history
  • Loading branch information
Patrick Mirwald committed Aug 15, 2024
1 parent 049a82c commit f0f085e
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion src/main/kotlin/com/liftric/octopusdeploy/shell.kt
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,21 @@ internal fun shell(cmd: String, logger: Logger): ShellResult = File(".").shell(c

internal fun File.shell(cmd: String, logger: Logger): ShellResult {
val tmpDir = System.getProperty("java.io.tmpdir")
val env = System.getenv().toMutableMap()

// Ensure PATH includes GITHUB_PATH if it exists
env["GITHUB_PATH"]?.let { githubPath ->
env["PATH"] = "${env["PATH"]}:$githubPath"
}

// DOTNET_BUNDLE_EXTRACT_BASE_DIR is a workaround for https://github.com/dotnet/runtime/issues/3846
val cmdarray = arrayOf("sh", "-c", "DOTNET_BUNDLE_EXTRACT_BASE_DIR=$tmpDir $cmd")
val cmdDir = this
logger.debug("shell: cmdarray='${cmdarray.toList()}'")
logger.debug("shell: cmdDir='$cmdDir'")
logger.debug("shell: tmpDir='$tmpDir'")
val process = Runtime.getRuntime().exec(cmdarray, emptyArray(), cmdDir)
val envArray = env.map { (key, value) -> "$key=$value" }.toTypedArray()
val process = Runtime.getRuntime().exec(cmdarray, envArray, cmdDir)
val exitCode = process.waitFor()
val inputText = process.inputStream.bufferedReader().readText().trim()
val errorText = process.errorStream.bufferedReader().readText().trim()
Expand Down

0 comments on commit f0f085e

Please sign in to comment.