Beispiel #1
0
        public Task <ExitCode> ExecuteAsync(
            ILogger logger,
            IReadOnlyCollection <IVariable> buildVariables,
            CancellationToken cancellationToken)
        {
            bool enabled = buildVariables.GetBooleanByKey(WellKnownVariables.ExternalTools_NuGetServer_Enabled, false);
            bool websitePackagesUploadEnabled =
                buildVariables.GetBooleanByKey(
                    WellKnownVariables.ExternalTools_NuGetServer_WebSitePackagesUploadEnabled,
                    false);

            if (!enabled)
            {
                logger.Write($"NuGet package upload is disabled ('{WellKnownVariables.ExternalTools_NuGetServer_Enabled}')");
                return(Task.FromResult(ExitCode.Success));
            }

            IVariable artifacts = buildVariables.Require(WellKnownVariables.Artifacts).ThrowIfEmptyValue();

            var packagesFolder    = new DirectoryInfo(Path.Combine(artifacts.Value, "packages"));
            var websitesDirectory = new DirectoryInfo(Path.Combine(artifacts.Value, "websites"));

            IVariable nugetExe = buildVariables.Require(WellKnownVariables.ExternalTools_NuGet_ExePath)
                                 .ThrowIfEmptyValue();
            string nugetServer =
                buildVariables.GetVariableValueOrDefault(
                    WellKnownVariables.ExternalTools_NuGetServer_Uri,
                    string.Empty);
            string nuGetServerApiKey =
                buildVariables.GetVariableValueOrDefault(
                    WellKnownVariables.ExternalTools_NuGetServer_ApiKey,
                    string.Empty);

            IVariable isRunningOnBuildAgentVariable =
                buildVariables.Require(WellKnownVariables.IsRunningOnBuildAgent).ThrowIfEmptyValue();

            bool isRunningOnBuildAgent = isRunningOnBuildAgentVariable.GetValueOrDefault(false);
            bool forceUpload           =
                buildVariables.GetBooleanByKey(WellKnownVariables.ExternalTools_NuGetServer_ForceUploadEnabled, false);

            bool timeoutIncreaseEnabled =
                buildVariables.GetBooleanByKey(WellKnownVariables.ExternalTools_NuGetServer_UploadTimeoutIncreaseEnabled, false);

            int timeoutInSeconds =
                buildVariables.GetInt32ByKey(WellKnownVariables.ExternalTools_NuGetServer_UploadTimeoutInSeconds, -1);

            bool checkNuGetPackagesExists =
                buildVariables.GetBooleanByKey(WellKnownVariables.ExternalTools_NuGetServer_CheckPackageExists, false);
            string sourceName =
                buildVariables.GetVariableValueOrDefault(
                    WellKnownVariables.ExternalTools_NuGetServer_SourceName,
                    string.Empty);

            if (isRunningOnBuildAgent)
            {
                logger.Write("NuGet package upload is enabled");
            }

            if (!isRunningOnBuildAgent && forceUpload)
            {
                logger.Write(
                    $"NuGet package upload is enabled by the flag '{WellKnownVariables.ExternalTools_NuGetServer_ForceUploadEnabled}'");
            }

            if (isRunningOnBuildAgent || forceUpload)
            {
                return(UploadNuGetPackagesAsync(
                           logger,
                           packagesFolder,
                           nugetExe.Value,
                           nugetServer,
                           nuGetServerApiKey,
                           websitePackagesUploadEnabled,
                           websitesDirectory,
                           timeoutInSeconds,
                           checkNuGetPackagesExists,
                           sourceName,
                           timeoutIncreaseEnabled));
            }

            logger.Write(
                $"Not running on build server. Skipped package upload. Set environment variable '{WellKnownVariables.ExternalTools_NuGetServer_ForceUploadEnabled}' to value 'true' to force package upload");

            return(Task.FromResult(ExitCode.Success));
        }
Beispiel #2
0
        public async Task <ExitCode> ExecuteAsync(
            ILogger logger,
            IReadOnlyCollection <IVariable> buildVariables,
            CancellationToken cancellationToken)
        {
            bool enabled = buildVariables.GetBooleanByKey(WellKnownVariables.NUnitEnabled, true);

            if (!enabled)
            {
                logger.WriteWarning("NUnit not enabled");
                return(ExitCode.Success);
            }

            IVariable externalTools = buildVariables.Require(WellKnownVariables.ExternalTools).ThrowIfEmptyValue();
            IVariable reportPath    = buildVariables.Require(WellKnownVariables.ReportPath).ThrowIfEmptyValue();

            _exePathOverride  = buildVariables.GetVariableValueOrDefault(WellKnownVariables.NUnitExePathOverride, string.Empty);
            _transformToJunit = buildVariables.GetBooleanByKey(WellKnownVariables.NUnitTransformToJunitEnabled, false);

            IVariable ignoreTestFailuresVariable =
                buildVariables.SingleOrDefault(key => key.Key == WellKnownVariables.IgnoreTestFailures);

            bool testsEnabled = buildVariables.GetBooleanByKey(WellKnownVariables.TestsEnabled, true);

            _sourceRoot = buildVariables.Require(WellKnownVariables.SourceRoot).ThrowIfEmptyValue().Value;

            if (!testsEnabled)
            {
                logger.WriteWarning(
                    $"Tests are disabled (build variable '{WellKnownVariables.TestsEnabled}' is false)");
                return(ExitCode.Success);
            }

            bool runTestsInReleaseConfiguration =
                buildVariables.GetBooleanByKey(
                    WellKnownVariables.RunTestsInReleaseConfigurationEnabled,
                    true);

            bool ignoreTestFailures = ignoreTestFailuresVariable.GetValueOrDefault(false);

            string assemblyFilePrefix = buildVariables.GetVariableValueOrDefault(WellKnownVariables.TestsAssemblyStartsWith, string.Empty);

            if (ignoreTestFailures)
            {
                string message =
                    $"The exit code from NUnit test was not successful, but the environment variable {WellKnownVariables.IgnoreTestFailures} is set to true, thus returning success";

                try
                {
                    ExitCode exitCode = await RunNUnitAsync(
                        externalTools,
                        logger,
                        reportPath,
                        runTestsInReleaseConfiguration,
                        assemblyFilePrefix);

                    if (exitCode.IsSuccess)
                    {
                        return(exitCode);
                    }

                    logger.WriteWarning(message);

                    return(ExitCode.Success);
                }
                catch (Exception ex)
                {
                    logger.WriteWarning($"{message}. {ex}");
                }

                return(ExitCode.Success);
            }

            return(await RunNUnitAsync(externalTools, logger, reportPath, runTestsInReleaseConfiguration, assemblyFilePrefix));
        }
Beispiel #3
0
        public Task <ExitCode> ExecuteAsync(
            ILogger logger,
            IReadOnlyCollection <IVariable> buildVariables,
            CancellationToken cancellationToken)
        {
            bool enabled = buildVariables.GetBooleanByKey(
                WellKnownVariables.ExternalTools_SymbolServer_Enabled,
                false);

            if (!enabled)
            {
                logger.Write("Symbol package upload is disabled");
                return(Task.FromResult(ExitCode.Success));
            }

            IVariable artifacts = buildVariables.Require(WellKnownVariables.Artifacts).ThrowIfEmptyValue();

            var packagesFolder = new DirectoryInfo(Path.Combine(artifacts.Value, "packages"));

            if (!packagesFolder.Exists)
            {
                logger.WriteWarning("There is no packages folder, skipping package upload");
                return(Task.FromResult(ExitCode.Success));
            }

            IVariable nugetExe =
                buildVariables.Require(WellKnownVariables.ExternalTools_NuGet_ExePath).ThrowIfEmptyValue();
            IVariable symbolServer =
                buildVariables.Require(WellKnownVariables.ExternalTools_SymbolServer_Uri).ThrowIfEmptyValue();
            IVariable symbolServerApiKey =
                buildVariables.Require(WellKnownVariables.ExternalTools_SymbolServer_ApiKey).ThrowIfEmptyValue();

            IVariable isRunningOnBuildAgentVariable =
                buildVariables.Require(WellKnownVariables.IsRunningOnBuildAgent).ThrowIfEmptyValue();

            bool isRunningOnBuildAgent = isRunningOnBuildAgentVariable.GetValueOrDefault(false);
            bool forceUpload           =
                buildVariables.GetBooleanByKey(
                    WellKnownVariables.ExternalTools_SymbolServer_ForceUploadEnabled,
                    false);

            int timeout =
                buildVariables.GetInt32ByKey(
                    WellKnownVariables.ExternalTools_SymbolServer_UploadTimeoutInSeconds,
                    -1);

            if (isRunningOnBuildAgent)
            {
                logger.Write("Symbol package upload is enabled");
            }

            if (!isRunningOnBuildAgent && forceUpload)
            {
                logger.Write(
                    $"Symbol package upload is enabled by the flag '{WellKnownVariables.ExternalTools_SymbolServer_ForceUploadEnabled}'");
            }

            if (isRunningOnBuildAgent || forceUpload)
            {
                return(UploadNuGetPackagesAsync(
                           logger,
                           packagesFolder.FullName,
                           nugetExe.Value,
                           symbolServer.Value,
                           symbolServerApiKey.Value,
                           timeout));
            }

            logger.Write("Not running on build server. Skipped package upload");

            return(Task.FromResult(ExitCode.Success));
        }