Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Assign Global Variable/Argument for Any Build to Use

I have several (15 or so) builds which all reference the same string of text in their respective build process templates. Every 90 days that text expires and needs to be updated in each of the templates. Is there a way to create a central variable or argument

like image 652
Steve L. Avatar asked Apr 17 '13 15:04

Steve L.


People also ask

How do you assign a variable globally?

Normally, when you create a variable inside a function, that variable is local, and can only be used inside that function. To create a global variable inside a function, you can use the global keyword.

Can global variables be used anywhere?

You can access the global variables from anywhere in the program. However, you can only access the local variables from the function. Additionally, if you need to change a global variable from a function, you need to declare that the variable is global. You can do this using the "global" keyword.

Is it better to use more no of global variables?

Using global variables causes very tight coupling of code. Using global variables causes namespace pollution. This may lead to unnecessarily reassigning a global value. Testing in programs using global variables can be a huge pain as it is difficult to decouple them when testing.

Can you use global variables in assembly?

Global variables are valuable time savers when it comes to using SolidWorks. They can save you loads of time when modeling. Not only can it save you time when modeling your parts, you can also use this tool in your assemblies to make updates to multiple parts with the change of a single global variable.


2 Answers

One solution would be to create an environment variable on your build machine. Then reference the variable in all of your builds. When you needed to update the value you would only have to set it in one place.

How to: Use Environment Variables in a Build

If you have more than one build machine then it could become too much of a maintenance issue.

Another solution would involve using MSBuild response files. You create an .rsp file that holds the property value and the value would be picked up and set from MSBuild via the command line.

like image 102
SoftwareCarpenter Avatar answered Sep 28 '22 05:09

SoftwareCarpenter


You need to place it into somewhere where all your builds can access it, then customize your build process template to read from there (build definitions - as you know - do not have a mechanism to share data between defs).

Some examples would be a file checked into TFS, a file in a known location (file share), web page, web service, etc.

You could even make a custom activity that knew how to read it and output the result as an OutArgument (e.g. Custom activity that read the string from a hardcoded URL).

like image 35
Dylan Smith Avatar answered Sep 28 '22 06:09

Dylan Smith