I commented to explain the lines/blocks of code as well as I could. You will use this in a PowerShell script step in a deployment/runbook where you want to edit/create a variable. The only input you should have to do is two sections. You will need to input your server, API key, and project name. The second thing you will need to do is just add any number of Modify-Variable/Add-Variable commands with the desired parameters(scopes are not mandatory but I included them in case you wanted to use them). You can look at my examples towards the bottom of the script.
This script you will put in later deployments in a PowerShell script step to refer back to the variables you stored earlier. You will have to put in the same 3 pieces of info as the last script, the url, api key, and project name where the variable is stored that you want to find. In this script you will call Find-Variable with all 3 parameters as in the example (always use $VariableToStore). Then you can use that variable in whatever method you’d like within the script.
Please let me know if this is useful for the scenario you are trying to solve or if you need any explanation/help with the above. As always please read the code and test it so that you’re comfortable with it. It would be good practice to make a dummy project and run the script in various ways and see how the variables within that project get altered and make sure you’re happy with the results.
If you had scoped the variable in the first part, in the second part when you retrieve it does Find-Variable need some extra logic to find the correct scoped variable?
I think I would need scoping, so that the project setting the variable could be run in parallel to different locations without overwriting the same variable.
Another idea, could the release generate an Artifact with the output values wanted, say a json file.
And then programmatically retrieve the release Artifact from the release?
With the ability to either get the Artifact from the release that has just run, or if the same package version had already been deployed to that environment to get the Artifact from the release that was previously deployed to that environment?
You are correct, if the variable is scoped, then extra logic will need to be added to search on and only return the desired scope. The current functionality will only look at if the name matches. So any further logic you will probably need to add yourself. If you have questions let me know.
Regarding artifacts, the process you are describing is absolutely possible, but it will require quite a bit of logic. I will paste you an example of artifact manipulation to get you started. I have also linked a couple examples of API calls to get you started. Please let me know if you have any other questions.
I just wanted to let you know I was able to add that functionality to my Find-Variable script. I edited the post above to reflect the new code. It should now check scopes, and prioritize scoped variables. As always, please read the code and test in a test environment to make sure you’re getting desired results. Let me know if you have any questions.