Search in sources :

Example 1 with PowerShellExecutionMode

use of jetbrains.buildServer.powershell.common.PowerShellExecutionMode in project teamcity-powershell by JetBrains.

the class BasePowerShellService method makeProgramCommandLine.

@NotNull
@Override
public ProgramCommandLine makeProgramCommandLine() throws RunBuildException {
    final PowerShellInfo info = selectTool();
    final BuildProgressLogger buildLogger = getBuild().getBuildLogger();
    final String psExecutable = info.getExecutablePath();
    final String workDir = getWorkingDirectory().getPath();
    final PowerShellExecutionMode mode = PowerShellExecutionMode.fromString(getRunnerParameters().get(RUNNER_EXECUTION_MODE));
    buildLogger.message("PowerShell Executable: " + psExecutable);
    buildLogger.message("Working directory: " + workDir);
    if (PowerShellExecutionMode.STDIN == mode) {
        return getStdInCommandLine(info, getEnv(info), workDir, generateCommand(info));
    } else if (PowerShellExecutionMode.PS1 == mode) {
        return getFileCommandLine(info, getEnv(info), workDir, generateArguments(info));
    } else {
        throw new RunBuildException("Could not select PowerShell tool for mode [" + mode + "]");
    }
}
Also used : BuildProgressLogger(jetbrains.buildServer.agent.BuildProgressLogger) PowerShellInfo(jetbrains.buildServer.powershell.agent.detect.PowerShellInfo) RunBuildException(jetbrains.buildServer.RunBuildException) PowerShellExecutionMode(jetbrains.buildServer.powershell.common.PowerShellExecutionMode) NotNull(org.jetbrains.annotations.NotNull)

Example 2 with PowerShellExecutionMode

use of jetbrains.buildServer.powershell.common.PowerShellExecutionMode in project teamcity-powershell by JetBrains.

the class PowerShellCommandLineProvider method provideCommandLine.

@NotNull
public List<String> provideCommandLine(@NotNull final PowerShellInfo info, @NotNull final Map<String, String> runnerParams, @NotNull final File scriptFile, final boolean useExecutionPolicy) throws RunBuildException {
    final List<String> result = new ArrayList<String>();
    final PowerShellExecutionMode mod = PowerShellExecutionMode.fromString(runnerParams.get(RUNNER_EXECUTION_MODE));
    if (mod == null) {
        throw new RunBuildException("'" + RUNNER_EXECUTION_MODE + "' runner parameter is not defined");
    }
    // version must be the 1st arg after executable path
    addVersion(result, runnerParams, info);
    if (!StringUtil.isEmptyOrSpaces(runnerParams.get(RUNNER_NO_PROFILE))) {
        result.add("-NoProfile");
    }
    result.add("-NonInteractive");
    addCustomArguments(result, runnerParams, RUNNER_CUSTOM_ARGUMENTS);
    if (useExecutionPolicy) {
        addExecutionPolicyPreference(result);
    }
    addScriptBody(result, mod, scriptFile, runnerParams);
    return result;
}
Also used : ArrayList(java.util.ArrayList) RunBuildException(jetbrains.buildServer.RunBuildException) PowerShellExecutionMode(jetbrains.buildServer.powershell.common.PowerShellExecutionMode) NotNull(org.jetbrains.annotations.NotNull)

Aggregations

RunBuildException (jetbrains.buildServer.RunBuildException)2 PowerShellExecutionMode (jetbrains.buildServer.powershell.common.PowerShellExecutionMode)2 NotNull (org.jetbrains.annotations.NotNull)2 ArrayList (java.util.ArrayList)1 BuildProgressLogger (jetbrains.buildServer.agent.BuildProgressLogger)1 PowerShellInfo (jetbrains.buildServer.powershell.agent.detect.PowerShellInfo)1