Search in sources :

Example 1 with BuildProgressLogger

use of jetbrains.buildServer.agent.BuildProgressLogger 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 BuildProgressLogger

use of jetbrains.buildServer.agent.BuildProgressLogger in project teamcity-powershell by JetBrains.

the class BasePowerShellService method getListeners.

@NotNull
@Override
public List<ProcessListener> getListeners() {
    final boolean logToError = !StringUtil.isEmptyOrSpaces(getRunnerParameters().get(PowerShellConstants.RUNNER_LOG_ERR_TO_ERROR));
    final BuildProgressLogger logger = getLogger();
    return Collections.<ProcessListener>singletonList(new ProcessListenerAdapter() {

        private final org.apache.log4j.Logger OUT_LOG = org.apache.log4j.Logger.getLogger("teamcity.out");

        @Override
        public void onStandardOutput(@NotNull final String text) {
            logger.message(text);
            OUT_LOG.info(text);
        }

        @Override
        public void onErrorOutput(@NotNull final String text) {
            if (logToError) {
                logger.error(text);
            } else {
                logger.warning(text);
            }
            OUT_LOG.warn(text);
        }
    });
}
Also used : BuildProgressLogger(jetbrains.buildServer.agent.BuildProgressLogger) NotNull(org.jetbrains.annotations.NotNull)

Example 3 with BuildProgressLogger

use of jetbrains.buildServer.agent.BuildProgressLogger in project teamcity-powershell by JetBrains.

the class BasePowerShellService method selectTool.

private PowerShellInfo selectTool() throws RunBuildException {
    final BuildProgressLogger buildLogger = getBuild().getBuildLogger();
    PowerShellInfo result;
    if (getRunnerContext().isVirtualContext()) {
        if (SystemInfo.isWindows) {
            throw new RunBuildException("PowerShell is not supported on windows containers");
        }
        buildLogger.logMessage(internalize(createTextMessage("PowerShell is running in virtual agent context")));
        result = VirtualPowerShellSupport.getVirtualPowerShell();
    } else {
        buildLogger.logMessage(internalize(createTextMessage("PowerShell running in non-virtual agent context")));
        final PowerShellBitness bit = PowerShellBitness.fromString(getRunnerParameters().get(RUNNER_BITNESS));
        final String version = getRunnerParameters().get(RUNNER_MIN_VERSION);
        final PowerShellEdition edition = PowerShellEdition.fromString(getRunnerParameters().get(RUNNER_EDITION));
        result = myInfoProvider.selectTool(bit, version, edition);
        if (result == null) {
            throw new RunBuildException("Could not select PowerShell for given bitness " + (bit == null ? "<Auto>" : bit.getDisplayName() + " and version " + (version == null ? "<Any>" : version)));
        }
    }
    return result;
}
Also used : PowerShellEdition(jetbrains.buildServer.powershell.common.PowerShellEdition) BuildProgressLogger(jetbrains.buildServer.agent.BuildProgressLogger) PowerShellInfo(jetbrains.buildServer.powershell.agent.detect.PowerShellInfo) RunBuildException(jetbrains.buildServer.RunBuildException) PowerShellBitness(jetbrains.buildServer.powershell.common.PowerShellBitness)

Example 4 with BuildProgressLogger

use of jetbrains.buildServer.agent.BuildProgressLogger in project teamcity-powershell by JetBrains.

the class PowerShellServiceUnix method executeWithWrapper.

private SimpleProgramCommandLine executeWithWrapper(@NotNull final Map<String, String> env, @NotNull final String workDir, @NotNull final String argsList) throws RunBuildException {
    final File scriptFile = generateNixScriptFile(argsList);
    final BuildProgressLogger buildLogger = getBuild().getBuildLogger();
    buildLogger.message("Wrapper script: " + scriptFile);
    buildLogger.message("Command: " + argsList);
    enableExecution(scriptFile);
    return new SimpleProgramCommandLine(env, workDir, scriptFile.getAbsolutePath(), Collections.<String>emptyList());
}
Also used : BuildProgressLogger(jetbrains.buildServer.agent.BuildProgressLogger) File(java.io.File) SimpleProgramCommandLine(jetbrains.buildServer.agent.runner.SimpleProgramCommandLine)

Example 5 with BuildProgressLogger

use of jetbrains.buildServer.agent.BuildProgressLogger in project teamcity-powershell by JetBrains.

the class PowerShellServiceWindows method getStdInCommandLine.

@Override
protected SimpleProgramCommandLine getStdInCommandLine(@NotNull final PowerShellInfo info, @NotNull final Map<String, String> env, @NotNull final String workDir, @NotNull final String command) throws RunBuildException {
    final List<String> args = generateRunScriptArguments(command);
    final String executable = myCommands.getCMDWrappedCommand(info, getEnvironmentVariables());
    final BuildProgressLogger buildLogger = getBuild().getBuildLogger();
    buildLogger.message("Executable wrapper: " + executable);
    buildLogger.message("Wrapper arguments: " + Arrays.toString(args.toArray()));
    buildLogger.message("Command: " + command);
    return new SimpleProgramCommandLine(env, workDir, executable, args);
}
Also used : BuildProgressLogger(jetbrains.buildServer.agent.BuildProgressLogger) SimpleProgramCommandLine(jetbrains.buildServer.agent.runner.SimpleProgramCommandLine)

Aggregations

BuildProgressLogger (jetbrains.buildServer.agent.BuildProgressLogger)7 SimpleProgramCommandLine (jetbrains.buildServer.agent.runner.SimpleProgramCommandLine)3 File (java.io.File)2 RunBuildException (jetbrains.buildServer.RunBuildException)2 PowerShellInfo (jetbrains.buildServer.powershell.agent.detect.PowerShellInfo)2 NotNull (org.jetbrains.annotations.NotNull)2 IOException (java.io.IOException)1 ServletOutputStream (javax.servlet.ServletOutputStream)1 HttpServlet (javax.servlet.http.HttpServlet)1 HttpServletRequest (javax.servlet.http.HttpServletRequest)1 HttpServletResponse (javax.servlet.http.HttpServletResponse)1 AgentRunningBuild (jetbrains.buildServer.agent.AgentRunningBuild)1 BuildAgentConfiguration (jetbrains.buildServer.agent.BuildAgentConfiguration)1 PowerShellBitness (jetbrains.buildServer.powershell.common.PowerShellBitness)1 PowerShellEdition (jetbrains.buildServer.powershell.common.PowerShellEdition)1 PowerShellExecutionMode (jetbrains.buildServer.powershell.common.PowerShellExecutionMode)1 LeechSettings (jetbrains.buildServer.torrent.settings.LeechSettings)1 TorrentsDownloadStatistic (jetbrains.buildServer.torrent.util.TorrentsDownloadStatistic)1 HttpClient (org.apache.commons.httpclient.HttpClient)1 Server (org.eclipse.jetty.server.Server)1