Using Account Username/Passwords in project variables

Hi,

How can i use Usernames/Passwords under Infrastructure > Accounts to set project variables when deploying to specific targets?

The deployments are tenanted deployments however username/password are unique to each target in the production environment.

Hi Sean,

Thank you for your question!

The Usernames/Passwords account type is only used for SSH connections, and can’t be used with variable substitution. However, you should be able to use normal variables for these usernames and passwords. Is something preventing this?

Regards,
Jayden

Hi Jayden,

Thanks for your reply.

The username and passwords are referenced by multiple projects, Since I am setting these values from Powershell i was hoping to only update/create a ‘global’ variable referenced by multiple projects rather than setting each individual project.

I think i will just have to update each project - thanks!

Hi Sean,

A Library Variable Set will allow you to define the variables in one place and then share them among as many projects as you need. You can still scope library variables to targets. Can you use them instead?

Regards,
Jayden

Hi Jayden,

This should work. I am having some issues adding a scope to the Library Variable Set via PowerShell based on this example

Do you know how i can attach the machine name into the VariableScopeValues machines list?

$libraryVariableSetId = “LibraryVariableSets-21” # Get this from /api/libraryvariablesets
$variableName = “test” # Name of the new variable
$variableValue = “1234” # Value of the new variable

$endpoint = new-object Octopus.Client.OctopusServerEndpoint $octopusURI,$apikey
$repository = new-object Octopus.Client.OctopusRepository $endpoint

$libraryVariableSet = $repository.LibraryVariableSets.Get($libraryVariableSetId);
$variables = $repository.VariableSets.Get($libraryVariableSet.VariableSetId);
$scope = new-object Octopus.Client.Model.VariableScopeValues
$scope.Machines.Add(‘awstest04’)

$myNewVariable = new-object Octopus.Client.Model.VariableResource
$myNewVariable.Name = $variableName
$myNewVariable.Value = $variableValue
$myNewVariable.Scope.Add($scope)

$variables.Variables.Add($myNewVariable)
$repository.VariableSets.Modify($variables)

It appears to accept a type of ReferenceDataItem however, I have not found any examples on data type ‘ReferenceDataItem’ in the GitHub documentation.

Cannot find an overload for “Add” and the argument count: “1”.
At line:19 char:1

  • $scope.Machines.Add(‘awstest04’)

Hi Sean,

The Scope property on variables is of type ScopeSpecification, rather than VariableScopeValues.

You also need to use the machine ID, not its name, which will look something like Machines-123

Try this in your example and you should get better results:

$myNewVariable = new-object Octopus.Client.Model.VariableResource
$myNewVariable.Name = $variableName
$myNewVariable.Value = $variableValue
$myNewVariable.Scope = new-object Octopus.Client.Model.ScopeSpecification
$myNewVariable.Scope.Add([Octopus.Client.Model.ScopeField]::Machine, (New-Object Octopus.Client.Model.ScopeValue("Machines-123"))

I hope that helps!

Regards,
Jayden

Jayden,

Perfect. Thanks for your help!

Sean,

No problem! Let me know if I can assist with anything else.

Regards,
Jayden

Hi Jayden,

I have ran into another issue. Since the variable library sets are per target now and referenced from each project. When i provision a new target a variable is added into the set and scoped to that target. I then have to create a new release to reference the updated value for every project - is there any way around not having to create a new release?

Thanks,
Sean

Hi Sean,

There certainly is! I’m assuming you are referring to manually updating the snapshotted variables for a release. On the release screen, there is a link you can click labelled “Update variables”. This will update the snapshotted variables for that release to the latest from all sources.

If you mean that you wish to automatically update the variable snapshots for a set of releases, that is definitely possible via the API as well but is more complex. If that is the case, let me know and we can work through that together.

Regards,
Jayden

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