Octopus.Client: Sensitive variables get erased when saving VariableSet

I have written a small .NET WinForms application to manipulate the Variables of a project. One button reads the VariableSet from an Octopus Project and writes an XLSX file containing the scope definitions, and the variables arranged in a crosstab by scope; the other application button reads the Excel file and writes the variables back to the Octopus Project.

All was working well, until I decided to make some variables Sensitive. Now as I found out, and as is well stated in the documentation, you cannot get the value from behind a variable marked Sensitive. Which makes sense. So I want my app now to exclude the Sensitive variables from being written to the Excel file. I figured out how to do this. But now when writing back, the Excel file doesn’t include the Sensitive variables, and when written to the Octopus project, the Sensitive variables disappear!

This is the code I’m using for writing the variables back to the server:

Public Class OctopusVariableServerVariables
    ' Vars will be set by another function accessing this class
    Public Property Vars As Octopus.Client.Model.VariableSetResource
' ... stuff omitted
    Sub WriteToServer(URL As String, ApiKey As String, ProjectName As String)
        Dim endpoint = New Octopus.Client.OctopusServerEndpoint(URL, ApiKey)
        Dim repos = New Octopus.Client.OctopusRepository(endpoint)

        Dim project = repos.Projects.FindByName(ProjectName)
        If project Is Nothing Then
            Throw New ArgumentException("Could not find project {0}", ProjectName)
        End If

    End Sub

End Class

So once again, the question is when I call Modify how do I avoid it destroying Variables on the server that are not included in the VariableSet I’m writing?

Hi Rpresser,

What you need to do is include the sensitive variables in the variable set that you pass to the Modify method with a blank value, the API will get the original value from the original variable set prior to updates and apply that.

Hope that helps!


Thanks. It does help.

This is not working. I don’t think it ever worked properly.

I have tried setting each sensitive variable’s value to String.Empty and also tried setting it to Nothing. Each one blanks the sensitive variable on the server.

I’ve also tried removing the sensitive variables from Vars.Variables. This removes the variable completely from the server.

This problem makes my forms app useless, because it’s impossible to save the variable set if any are sensitive. All variable editing must now be done from the web page.

I am using Octopus 3.3.10 at the moment. We will probably upgrade after the first of the year, but will that fix the problem?


I’ve tested this again using a local 3.3.10 instance and Octopus.Client version 3.3.10 with a project that has sensitive variables and I’m not seeing the behavior you are experiencing. As long as the sensitive variable is included with a null value in the variable set that is posted back to the Octopus server it should leave them and their values intact.

I used the below code to test it out, not your exact scenario of writing/reading to/from an Excel spreadsheet but as long as the final variable set object that is passed to the server has the same structure it should be the same.

var repository = new Octopus.Client.OctopusRepository(endpoint);

var project = repository.Projects.FindByName("Variables Test");
var variableSet = repository.VariableSets.Get(project.VariableSetId); // this variable set has a sensitive value included
var newVariable = new Octopus.Client.Model.VariableResource();
newVariable.Name = "AnotherVariable";
newVariable.Value = "TheValue";

variableSet.Variables.Add(newVariable); // The sensitive variable is posted back with a value of null


Thank you,