Octopus 3.3.14, Windows Server 2012R2
Here’s the scenario - we’ve got a rolling deployment going out to X servers. We have integration tests we want to run against each server as we deploy to it. To do this, we execute a powershell script on the Octopus head server as the final child-step in the rolling deploy.
We want to grab the test report XML as an artifact of the deployment. However, the file isn’t showing up on the release. We had it working before we were running this on the head server in a rolling deployment. We also know the file exists, because we’re able to add a Copy-Item command and save the file off to a folder. And we still get a log message: “##octopus[createArtifact path=‘QzpcVGVtcFxPY3RvcHVzXERldmVsb3BtZW50LVRlc3RSZXN1bHRzLmh0bWw=’ name=‘QzpcVGVtcFxPY3RvcHVzXERldmVsb3BtZW50LVRlc3RSZXN1bHRzLmh0bWw=’ length=‘NTQwMDU=’]”
Is capturing artifacts from rolling deployment head server scripts supported? Are there any extra limitations there we have to watch out for?
Thanks for reaching out.
Could you share a screenshot of your deployment process where I can see all the steps, and then mark with an arrow or something the step where you are running the
New-OctopusArtifact cmdlet? I’m having a hard time trying to understand your scenario, and I believe that screenshot will allow me to try to reproduce it myself
Screenshot of deployment process with arrow attached. The offending powershell script is below:
$testPackageDir = $OctopusParameters['Octopus.Action[Deploy Integration Tests Package].Output.Package.InstallationDirectoryPath']
$environment = $OctopusParameters['Octopus.Environment.Name']
$env:TestTargetSiteSubDomain = $TestURLSubDomain
$nunit = "D:\Tools\NUnit2.6.3\bin\nunit-console.exe"
$reportUnit = "D:\Tools\ReportUnit.exe"
$testAssemblyPath = "$testPackageDir\lib\$TestAssembly"
$testResults = "C:\Temp\Octopus\$environment-TestResults.html"
Write-Host "Running tests with NUnit console at $nunit"
Write-Host "Against site at $TestURLSubDomain"
Write-Host "Using test assembly(ies): $testAssemblyPath"
Write-Host "Filtered by including: ($TestIncludeArgs) and excluding: ($TestExcludeArgs)"
Write-Host "Transforming output using report unit at $reportUnit"
Write-Host "Output file will be $testResults"
$testFailure = $false
& $nunit $testAssemblyPath /xml:TestResults.xml $TestIncludeArgs $TestExcludeArgs
$testFailure = $true
Copy-Item TestResults.xml C:\Temp\Octopus\ # <------- this works as intended - C:\Temp\Octopus contains TestResults.xml and the HTML output of report unit after it completes.
& $reportUnit TestResults.xml $testResults
New-OctopusArtifact -Path $testResults -Name $testResults # <------ this doesn't work - log message appears here, but no artifact appears.
Write-Error "Test failures! See artifact $testResults and deployment log for more details."
After running this code
One additional tidbit of info - is is possible that only successful deployments will record artifacts? The integration tests we’re currently running are failing, which causes us to then fail the deployment. If we run a smaller, successful set, then we do successfully get an artifact.
I’d recommend you to do the following in your case:
On that step “Run Web UI tests”, only run the tests and drop the file with the results somewhere in disk (on the Octopus Server). Do not create the Artifact at this point
Add a separate Powershell script step at the bottom of the deployment process that’s outside of the rolling steps. Set this step to run only if all previous steps were successful (option is right at the bottom of the step config), and add the
New-OctopusArtifact script in it.
That should solve the issue you were getting initially, and also achieve what you want to do which is only create the artifact when everything went just fine.
Ah, we actually want the opposite behavior though - we want to grab the test result artifact especially if the deployment fails, so it can help us diagnose the issues.
Your solution still works though - we just have the separate step “run always” instead of running on success.
If my hypothesis is correct, and Octopus will not upload artifacts from failing deployment steps, it might be useful to update the official docs to reflect that. I don’t currently see it mentioned anywhere.
Thanks for your help!