1

My connection strings are configured in Octopus Deploy through library/variables/LibraryVariableSets and all works fine based on the target environment, what I am going to do now is to create new db users for each project/app and set this UID/PWD in my connection strings in Octopus.

My question is: how can I configure this connection string per project like what I already have with the local variables for the project (app settings keys)?

P.S. Octopus version is 4.1.2

Ahmed Negm
  • 865
  • 1
  • 11
  • 30

2 Answers2

2

You can add variable references for the username and password to the connection string variable in Library Variable Set.

Server=myServerAddress;Database=myDataBase;User Id=#{dbuserid}; Password=#{dbpassword};

Then in each project where you are using this library variable set, create a new variables for the dbuserid and dbpassword, when the variables are evaluated for the deployment, these variable placesholders in the connection string will be updated with the values provided by the project variables.

The final value of the connection string variable during deployment:

Server=myServerAddress;Database=myDataBase;User Id=userid; Password=password;

More details:

This is what your library variable set should look like, you can add some scoping here too. Library Variable Set

Link the Library Variable Set to the project:

Library Variable Set link

Then set the user id and password in the project variables:

project variable values

Then you can use the connection string in scripts or as variable replacement in your config files.

I tested it with the following powershell script

write-host $connectionstring
write-host "#{connectionstring}"

Which results in the following output:

script output

If you need to inject the connection string into a specific position in a JSON file, you can use the JSON Configuration Variables syntax and set the value to the connection string variable reference #{connectionstring}.

json connection string example

benPearce
  • 37,735
  • 14
  • 62
  • 96
  • It seems good idea, but I couldn't do it, so, it would be great if you can guide me with links or steps ... what I can understand here is we will add a general connection sting with that variable of UID and PWD, then in the project's variables (app settings keys) I can re-declare the same variables with the same names along with the values which I need to have for this project ... correct? If not, kindly share the steps in order with me ... thank you in advance – Ahmed Negm Feb 21 '19 at 10:16
  • @AhmedNegm I have added all the steps needed and example screenshots – benPearce Feb 22 '19 at 01:00
1

Variables within library variable sets aren't able to be scoped to individual projects, as they're designed to be global across projects. There's an active UserVoice suggestion to implement this, however: https://octopusdeploy.uservoice.com/forums/170787-general/suggestions/31206961-library-variables-ability-to-scope-to-projects

You can currently define these variables within a set, and include that set into many projects if you want to define a default value. If you define a project variable with the same name, that will be considered more "specifically scoped" and thus be used when deploying. I don't think this will be of much help with things like connection strings that are project-specific.

SLTemplezz
  • 41
  • 1