Пример #1
0
        public static void ConfigureTfsEnvironment(ICakeContext ctx, TaskConfig cfg)
        {
            IAzurePipelinesProvider azurePipelines = ctx.AzurePipelines();

            ctx.LogInfo(azurePipelines.Dump());

            //if (!azurePipelines.IsRunningOnAzurePipelines || !azurePipelines.IsRunningOnAzurePipelinesHosted)
            //    throw new TaskConfigException("Not running in Azure Pipelines");

            EnvConfig env = cfg.Load <EnvConfig>();

            env.IsCi = true;

            // If the build number is configured as an integer, use it. Otherwise use the build ID.
            // Basically, we need something unique.
            env.Version.BuildNumber = azurePipelines.Environment.Build.Number;
        }
Пример #2
0
        public static void PublishTestResults(ICakeContext ctx)
        {
            IAzurePipelinesProvider azurePipelines = ctx.AzurePipelines();

            if (!azurePipelines.IsRunningOnAzurePipelines || !azurePipelines.IsRunningOnAzurePipelinesHosted)
            {
                return;
            }

            FilePathCollection trxFiles = ctx.GetFiles("./**/*.trx");

            if (trxFiles.Count == 0)
            {
                return;
            }

            int index = 0;

            foreach (FilePath trxFile in trxFiles)
            {
                string sourceFile  = trxFile.FullPath;
                string directory   = IO.Path.GetDirectoryName(sourceFile);
                string renamedFile = IO.Path.Combine(directory, $"TestResults{index}.trx");
                IO.File.Move(sourceFile, renamedFile);
                index++;
            }

            FilePathCollection testResultsFiles = ctx.GetFiles("./**/*.trx");

            foreach (FilePath filePath in testResultsFiles)
            {
                ctx.Log.Information(filePath.ToString());
            }

            azurePipelines.Commands.PublishTestResults(new AzurePipelinesPublishTestResultsData
            {
                TestRunner       = AzurePipelinesTestRunnerType.VSTest,
                TestResultsFiles = testResultsFiles.ToList(),
                MergeTestResults = true,
            });
        }