octopus-deploydbup

Problem Generating Html Report Using DbUp during Octopus Deployment


Using Octopus Deploy to deploy a simple API. The first step of our deployment process is to generate an HTML report with the delta of the scripts run vs the scripts required to run. I used this tutorial to create the step.

The relevant code in my console application is:

var reportLocationSection = appConfiguration.GetSection(previewReportCmdLineFlag);

if (reportLocationSection.Value is not null)
{
    // Generate a preview file so Octopus Deploy can generate an artifact for approvals
    try
    {
        var report = reportLocationSection.Value;

        var fullReportPath = Path.Combine(report, deltaReportName);

        Console.WriteLine($"Generating upgrade report at {fullReportPath}");

        upgrader.GenerateUpgradeHtmlReport(fullReportPath);

    }
    catch (Exception ex)
    {
        Console.WriteLine(ex.Message);
        return operationError;
    }
}

The Powershell which I am using in the script step is:

# Get the extracted path for the package
$packagePath = $OctopusParameters["Octopus.Action.Package[DatabaseUpdater].ExtractedPath"]
$connectionString = $OctopusParameters["Project.Database.ConnectionString"]
$reportPath = $OctopusParameters["Project.HtmlReport.Location"]

Write-Host "Report Path: $($reportPath)"

$exeToRun = "$($packagePath)\DatabaseUpdater.exe"
$generatedReport = "$($reportPath)\UpgradeReport.html"

Write-Host "Generated Report: $($generatedReport)"

if ((test-path $reportPath) -eq $false){    
    New-Item "Creating new directory..."
} else {
    New-Item "Directory already exists."
}

# Run this .NET app, passing in the Connection String and a flag
# which tells the app to create a report, but not update the database
& $exeToRun --connectionString="$($connectionString)" --previewReportPath="$($reportPath)"

New-OctopusArtifact -Path "$($generatedReport)"

The error reported by Octopus is:
'Could not find file 'C:\DeltaReports\Some API\2.9.15-DbUp-Test-9\UpgradeReport.html'.'

I'm guessing that is being thrown when this powershell line is hit: New-OctopusArtifact ... And that seems to indicate that the report was never created.

I've used a bit of logging to log out certain variables and the values look sound:

As you can see in the C#, the relevant code is wrapped in a try/catch block, but I'm not sure whether the error is being written out there or at a later point by Octopus (I'd need to do a pull request to add a marker in the code).

Can anyone see a way forward win resolving this? Has anyone else encountered this?

Cheers


Solution

  • After long and detailed investigation, we discovered the answer was quite obvious.
    We assumed the existing deploy process configuration was sound. Because we never had a problem with it (until now). As it transpires, there was a problem which led to the Development deployments being deployed twice.
    Hence, the errors like the one above and others which talked about file handles being held by another process.

    It was actually obvious in hindsight, but we were blind to it as we thought the existing process was sound 😣