Set-octous variable with datatable

I have tried to create datatable using powershell step 1 and did set-octopus variable after convertto-json method,
step 1:
Set-OctopusVariable -Name “datatable_values” -Value ($datatable | convertto-json)

step 2:

$dt = $OctopusParameters[“Octopus.Action[step1].output.datatable_values”]
$coverted_ dt = $dt | convertfrom-Json

{$converted_dt }returns empty values

kindly help me

Hi @YuvarajDuraisamy,

Thanks for getting in touch, and great question. I’m going to set up an attempt to reproduce this issue, however I did notice a couple subtle typos in your step two script that may be the culprit. Notice the space before dt in the variable name ($coverted_ dt), as well as the missing n in that same variable name differing from the the $converted_dt that’s returning empty.

If those are exactly matching in your setup, could you also send me how you’re defining the $datatable variable in your script? That should allow me to test this out exactly. :slight_smile:

Best regards,

Kenny

sorry typo mistake in the forum not in my script

$dt_appid = New-Object System.Data.DataTable
[void]$dt_appid.Columns.Add(“EnvironmentName”)
[void]$dt_appid.Columns.Add(“LabsiteName”)
[void]$dt_appid.Columns.Add(“ApplicationName”)
[void]$dt_appid.Columns.Add(“ComponentName”)
[void]$dt_appid.Columns.Add(“AppIdentifierName”)
[void]$dt_appid.Columns.Add(“CertificateName”)
[void]$dt_appid.Columns.Add(“ServerNames”)
[void]$dt_appid.Columns.Add(“VariableName”)
[void]$dt_appid.Columns.Add(“Status”)
[void]$dt_appid.Columns.Add(“Permissions”)
step 1:

Set-OctopusVariable -Name “created_dt_appid” -Value ($dt_appid | convertto-json)

step 2:

$to_be_created_dt = $OctopusParameters[“Octopus.Action[Generate Report].output.created_dt_appid”]

$create_appid = $to_be_created_dt | convertfrom-Json

$create_appid returns null

Hi @YuvarajDuraisamy,

Thanks for following up! Would you be willing to add the following debugging variables to your project, then create and deploy a new release? These variables will add verbose details to the resulting task log, and I’m hoping that sheds more light on what might be causing this issue.

If you’re able to produce this verbose task log, you can upload it to this secure link.

Best regards,

Kenny

uploaded log file and

[Octopus.Action[Generate Report].Output[server].created_dt_appid] – this output variable having the values as per the log file
when I try to read using this code
$to_be_created_dt = $OctopusParameters[“Octopus.Action[Generate Report].output.created_dt_appid”]

$create_appid = $to_be_created_dt | convertfrom-Json

write-host “create_appid values :” $create_appid

returns null

Good afternoon @YuvarajDuraisamy,

Just jumping in here for Kenny who is currently off shift as part of our Australian based team. Thank you for getting us the logs. I took a look and unfortunately they dont look like the full Octopus Task logs with variable logging turned on that Kenny linked in his previous response. Did you edit the logs due to security reasons by any chance?

Ideally we do need the full task log with variable logging turned on so we can see exactly what is going on here.

Another thing we did see is this line:

Set-OctopusVariable -Name "datatable_values" -Value ($datatable | convertto-json)

We are not sure if this will work since we store variables as strings, I am wondering if you could add a little bit extra to your script to see if this makes it work.

Placing $dt_appid | convertto-json into a new variable, then outputting the value of that variable, before then placing it in the output variable would work better. An example of this would be:

$testVariable = ($dt_appid | convertto-json)
write-output $testVariable
Set-OctopusVariable -Name "created_dt_appid" -Value $testVariable

Are you able to try something like that out and see if that solves the issue? If not can we get the full task logs with variable logging turned on please (you can use the same secure link Kenny posted up to upload the files) and we can take another look.

Kind Regards,

Clare

same issue still exists,

Due to security concern ,I am sending log file with minimal data

Thanks for sending that over.

It is quite difficult to help identify the problem without seeing the full task log though, however, from the snippet you provided it looks like write-output $testVariable isn’t outputting anything?

Which suggests that ($dt_appid | convertto-json) isn’t returning a value.

You may need to perform some additional troubleshooting with your script until the write-output $testVariable returns a value. At that point, you will then be able to add that value to the output variable and return it in the later step without issue.

Regards,
Paul

This topic was automatically closed 31 days after the last reply. New replies are no longer allowed.