use of jetbrains.buildServer.powershell.common.PowerShellScriptMode in project teamcity-powershell by JetBrains.
the class ScriptGenerator method generateScript.
/**
* Gets script source file either from parameter by dumping it to temp file
* or from file, specified in parameters
*
* @param runnerParameters runner parameters
* @param buildCheckoutDir checkout directory
* @param buildTempDir temp directory
* @return if {@code PowerShellScriptMode.FILE} is used - file, that corresponds to {@code RUNNER_SCRIPT_FILE} param,
* if {@code PowerShellScriptMode.CODE} is used - temp file, containing code from {@code RUNNER_SCRIPT_CODE} param
*
* @throws RunBuildException if value if {@code RUNNER_SCRIPT_CODE} param is empty, or file handling error occurred
*/
@NotNull
public File generateScript(@NotNull final Map<String, String> runnerParameters, @NotNull final File buildCheckoutDir, @NotNull final File buildTempDir) throws RunBuildException {
final PowerShellScriptMode scriptMode = PowerShellScriptMode.fromString(runnerParameters.get(RUNNER_SCRIPT_MODE));
File scriptFile;
if (PowerShellScriptMode.FILE == scriptMode) {
scriptFile = FileUtil.resolvePath(buildCheckoutDir, runnerParameters.get(RUNNER_SCRIPT_FILE));
} else {
String sourceScript = runnerParameters.get(RUNNER_SCRIPT_CODE);
if (isEmptyOrSpaces(sourceScript)) {
throw new RunBuildException("Empty build script");
}
sourceScript = convertLineSeparators(sourceScript, "\r\n");
/*if (PowerShellExecutionMode.STDIN.equals(PowerShellExecutionMode.fromString(runnerParameters.get(RUNNER_EXECUTION_MODE)))) {
//some newlines are necessary to workaround -Command - issues, like TW-19771
sourceScript = " \r\n \r\n \r\n" + sourceScript + "\r\n \r\n \r\n ";
}*/
scriptFile = writeToTempFile(buildTempDir, sourceScript, runnerParameters);
}
if (!scriptFile.isFile()) {
throw new RunBuildException("Cannot find PowerShell script by path specified in build configuration settings: " + scriptFile.getAbsolutePath() + " (absolute path on agent). Please check that the specified path is correct.");
}
return scriptFile;
}
Aggregations