Updating an existing template in version Octopus 3.11.11 cause object reference not set error

Trying to update an existing step template and while clicking on the Save button causes this error to display: Object reference not set to an instance of an object.

Hi Yenni,

Could you send through the JSON response when you view the step template that you’re trying to edit (as it looks like the parameters in the step template is missing a new property)?

We did a fix in 3.11.8 (which became 3.11.9) that should’ve populated this new field if it was missing.

Thank you and best regards,
Henrik

Json format:

{
“Id”: “ActionTemplates-33”,
“Name”: “Comcast Automated Test - SpecRunner By Categories”,
“Description”: “This step executes SpecRunner for automating functional tests by categories.”,
“ActionType”: “Octopus.Script”,
“Version”: 16,
“CommunityActionTemplateId”: null,
“Properties”: {
“Octopus.Action.Script.ScriptBody”: “function Invoke-Script($basePath, $functionalTestName, $profile, $filters, $specRunnerExe, $expectedTestSuccessRate, $machineRole, $resultFolder)\r\n{\r\n\tWrite-Host (“Determining which machine to run tests on…”)\r\n\t\r\n\ttry{\r\n\t\t$machine = Get-AvailableWorkerMachineFromPool $machineRole\r\n\t}\r\n\tcatch [System.Management.Automation.CommandNotFoundException]{\r\n\t\tthrow “Get-AvailableWorkerMachineFromPool module is not loaded in this project. Please use Project->Process->”“Include script modules”” link to select Get-AvailableWorkerMachineFromPool module."\r\n\t}\r\n\t\r\n\t\r\n\tif(!$machine){\r\n\t\tWrite-Host (“Machine $machine is not a designated runner machine for this release, exiting…”)\r\n\t\tExit 0\r\n\t}\r\n\t\r\n\tWrite-Host “Starting Test Run…”\r\n\t\r\n\t#Write-Host $specRunnerExe + " run $profile.srprofile /baseFolder:$basePath /filter:\"$filters" /log:specrun.log"\r\n\t$commandLine = “$specRunnerExe run default.srprofile /baseFolder:$basePath /filter:\"$filters” /log:specrun.log"\r\n\t\r\n\tWrite-Host $commandLine\r\n\tInvoke-Expression $commandLine | Tee-Object -Variable testResultsOutput | Out-Null\r\n\t\r\n\t$testResultsOutput = Get-Content -Path $basePath\specrun.log\r\n\r\n\t If (!(Test-Path $basePath\$resultFolder -PathType Container))\r\n\t {\r\n\t\tNew-Item -ItemType directory -Path $basePath\$resultFolder \r\n\t}\r\n\r\n\tCopy-Item “$basePath\.html" “$basePath\$resultFolder”\r\n\t"Copy files from $basePath\$functionalTestName.html to $basePath\$resultFolder”\r\n\t"Results are copied to $basePath\$resultFolder to be zipped up…"\r\n\r\n\t$testResults = Get-ParseTestResults $testResultsOutput\r\n\tWrite-Host “Parsed Test Result: $testResults”\r\n\tWrite-TestResults $testResults $expectedTestSuccessRate\r\n\tWrite-Host “Process exited with code $LASTEXITCODE”\r\n\tExit 0\r\n}\r\n###################################################################\r\n# Octopust Step Template Helper functions section\r\n###################################################################\r\n\r\nfunction Get-TestResultNumber($testResults, $resultCategory){\r\n\t$result = ($testResults | select-string ($resultCategory + “: \d+”) -allmatches).matches\r\n\t$result = $result -split “:”\r\n\tif(!$result){\r\n\t\treturn 0\r\n\t}\r\n\treturn $result[1].Trim()\r\n}\r\n\r\nfunction Get-ParseTestResults($testResultsOutput){\r\n\t$properties = @{\r\n\t\tSucceeded = Get-TestResultNumber $testResultsOutput “Succeeded” \r\n\t\tFailed = Get-TestResultNumber $testResultsOutput “Failed”\r\n\t\tSkipped = Get-TestResultNumber $testResultsOutput “Skipped”\r\n\t\tPending = Get-TestResultNumber $testResultsOutput “Pending”\r\n\t\tIgnored = Get-TestResultNumber $testResultsOutput “Ignored”\r\n\t\tTotal = Get-TestResultNumber $testResultsOutput “Total” \r\n\t}\r\n\treturn New-Object PSObject -Property $properties\r\n}\r\nfunction Write-TestResults($testResults, $expectedTestSuccessRate = 100){\r\n\t\r\n\tif($testResults.Total -eq 0){\r\n\t\tWrite-Host “No tests found to execute.”\r\n\t\tExit 0\r\n\t}\r\n\t$recalTotal = [int]$testResults.Total - [int]$testResults.Ignored\r\n\t$testsPassRate = (($testResults.Succeeded / $recalTotal) * 100)\r\n\tWrite-Host ("----------------------------------------")\r\n\tWrite-Host ("Total tests executed: " + $recalTotal)\r\n\tWrite-Host ("Tests passed: " + $testResults.Succeeded)\r\n\tWrite-Host ("Tests failed: " + $testResults.Failed)\r\n\tWrite-Host (“Tests skipped: " + $testResults.Skipped)\r\n\tWrite-Host (“Tests pending: " + $testResults.Pending)\r\n\tWrite-Host (“Tests ignored: " + $testResults.Ignored)\r\n\tWrite-Host (“Tests expected pass rate: $expectedTestSuccessRate%”)\r\n\tWrite-Host (“Total Tests actual pass rate minus Ignore Counts: $testsPassRate %”)\r\n\tif($testsPassRate -ge $expectedTestSuccessRate)\r\n\t{\r\n\t\tWrite-Host “Number of tests passed is equal or above expected rate.”\r\n\t\tExit 0\r\n\t}\r\n\telse{\r\n\t\tWrite-Host “Number of tests passed is below expected rate. Declaring as failed!”\r\n\t\tExit 1 \r\n\t}\r\n}\r\n###################################################################\r\n# Setup parameters\r\n# NOTE: Uncomment below line to use the parameters\r\n###################################################################\r\n#$$basePath = “C:\Dev\CI\Dev\BSEE\Comcast.Business.Functional.Tests\15.12.01.66”\r\n#$functionalTestName = “comcast.business.functional.tests”\r\n#$executionPath = “$basePath/$functionalTestName”\r\n#$profile =“default”\r\n#$filters = “@smoke”\r\n#$specRunnerExe = “C:\Programs\SpecRunner\tools\SpecRun.exe”\r\n\r\n###################################################################\r\n# Tell Octopus to launch script\r\n# NOTE: Uncomment below line to execute within Octopus Deploy\r\n###################################################################\r\n\r\nInvoke-Script $basePath $functionalTestName $profile $filters $specRunPath $expectedTestSuccessRate $machineRole $resultFolder\r\n\r\n\r\n”,
“Octopus.Action.Script.Syntax”: “PowerShell”,
“Octopus.Action.Script.ScriptSource”: “Inline”,
“Octopus.Action.RunOnServer”: “false”,
“Octopus.Action.Script.ScriptFileName”: null,
“Octopus.Action.Package.FeedId”: null,
“Octopus.Action.Package.PackageId”: null
},
“Parameters”: [
{
“Name”: “basePath”,
“Label”: “Base Path”,
“HelpText”: “The path of the root directory”,
“DefaultValue”: “”,
“DisplaySettings”: {
“Octopus.ControlType”: “SingleLineText”
},
“Links”: {}
},
{
“Name”: “functionalTestName”,
“Label”: “Functional Test Name”,
“HelpText”: “Name of the functional test”,
“DefaultValue”: “comcast.application.functional.tests”,
“DisplaySettings”: {
“Octopus.ControlType”: “SingleLineText”
},
“Links”: {}
},
{
“Name”: “profile”,
“Label”: “Profile”,
“HelpText”: “Profile for SpecRunner to run.”,
“DefaultValue”: “default”,
“DisplaySettings”: {
“Octopus.ControlType”: “SingleLineText”
},
“Links”: {}
},
{
“Name”: “filters”,
“Label”: “Filters”,
“HelpText”: “Categories for the filtering to execute. Example, can handle one more more (@smoke, @smoke & regression, @regression & @progression)”,
“DefaultValue”: “@smoke”,
“DisplaySettings”: {
“Octopus.ControlType”: “Select”,
“Octopus.SelectOptions”: “@smoke|Smoke\n@regression|Regression\n@prod-smoke|Prod-Smoke\n@prod-regression|Prod-Regression”
},
“Links”: {}
},
{
“Name”: “specRunPath”,
“Label”: “Spec Runner Path”,
“HelpText”: “Path to exe.”,
“DefaultValue”: “d:/Programs/SpecRunner/tools/SpecRun.exe”,
“DisplaySettings”: {
“Octopus.ControlType”: “SingleLineText”
},
“Links”: {}
},
{
“Name”: “expectedTestSuccessRate”,
“Label”: “Expected Test Success Rate”,
“HelpText”: “Provide a minimum percentage number 0-100 in order for the tests to pass. By default, all test must pass, 100%.”,
“DefaultValue”: “100”,
“DisplaySettings”: {
“Octopus.ControlType”: “SingleLineText”
},
“Links”: {}
},
{
“Name”: “machineRole”,
“Label”: “Machine Role”,
“HelpText”: “Provide a name of a single machine role as used in machine and environment configurations.”,
“DefaultValue”: “AutomatedTestRunnerServer”,
“DisplaySettings”: {
“Octopus.ControlType”: “SingleLineText”
},
“Links”: {}
},
{
“Name”: “resultFolder”,
“Label”: “Result Folder”,
“HelpText”: “Html and screenshots where it resides.”,
“DefaultValue”: “Results”,
“DisplaySettings”: {
“Octopus.ControlType”: “SingleLineText”
},
“Links”: {}
}
],
”$Meta”: {
“ExportedAt”: “2017-03-16T19:54:15.963Z”,
“OctopusVersion”: “3.10.0”,
“Type”: “ActionTemplate”
}
}

I found the the missing tag:

In the parameters list: Id’s is missing;
“Parameters”: [
{
“Name”: “basePath”,
“Label”: “Base Path”,
“HelpText”: “The path of the root directory”,
“DefaultValue”: “”,
“DisplaySettings”: {
“Octopus.ControlType”: “SingleLineText”
},
“Links”: {}
},

New Step Template
"Parameters": [
{
“Id”: “8d568b79-1989-4ddf-a552-a147237b2535”,
“Name”: “basePath”,
“Label”: “Base Path”,
“HelpText”: “The path of the root directory”,
“DefaultValue”: “”,
“DisplaySettings”: {
“Octopus.ControlType”: “SingleLineText”
},
“Links”: {}
},

We have 63 step templates. During the upgrade, shouldn’t it gone through all the existing templates and update all. Is there a script to allow us to update this in the database to help resolve this issue?

I found the the missing tag:

In the parameters list: Id’s is missing;
“Parameters”: [
{
“Name”: “basePath”,
“Label”: “Base Path”,
“HelpText”: “The path of the root directory”,
“DefaultValue”: “”,
“DisplaySettings”: {
“Octopus.ControlType”: “SingleLineText”
},
“Links”: {}
},

New Step Template
"Parameters": [
{
“Id”: “8d568b79-1989-4ddf-a552-a147237b2535”,
“Name”: “basePath”,
“Label”: “Base Path”,
“HelpText”: “The path of the root directory”,
“DefaultValue”: “”,
“DisplaySettings”: {
“Octopus.ControlType”: “SingleLineText”
},
“Links”: {}
},

We have 63 step templates. During the upgrade, shouldn’t it gone through all the existing templates and update all. Is there a script to allow us to update this in the database or an automated way to update these steps templates to include ID ->Autogenerated keys to help resolve this issue?

Thanks,
Yenni

Hi Yenni,

We do have a db upgrade script that should’ve populated that Id field when upgrading the server, but it looks like it hasn’t picked up your step templates for some reason.

Could you run the following SQL Query on your Octopus server:

SELECT *
  FROM [dbo].[SchemaVersions]

and let me know if the following script Octopus.Core.UpgradeScripts.Script0083SetMissingStepTemplateIdWhenIdIsNull.cs is in that table?

Also, could you send through your Octopus server logs so we can see if that has any errors in it relating to this?

Thank you and best regards,
Henrik

Hi Henrik,

Attached the OD server log and the error generated is at 09:59AM EST.
Also Attached the Screen Shot of the DB and executed the script and iam unable to see “Octopus.Core.UpgradeScripts.Script0083SetMissingStepTemplateIdWhenIdIsNull.cs”.

–Manojreddy

OctopusServer.txt (1 MB)

Hi Manojreddy,

Thanks for sending through that, can I confirm what version of Octopus you are running (a screenshot of the help menu, top right corner, will suffice) as there’s 4 DB upgrade scripts missing in your SchemaVersions table?

Thank you and best regards,
Henrik

Hi Henrik,

We are running 3.10.0 OD version

Hi Manojreddy,

Thanks for confirming that for me.

The issue you are having was fixed in 3.11.9.

Thank you and best regards,
Henrik