Our generic Maven build needs to pass on a number of properties to child processes.
Right now, we are providing these as environment variables, and reading them in individually as properties.
These properties are then substituted into a file to configure a test runtime, and provided to the Failsafe plugin as environment variables for the test run.
The above is fine, except for a couple of things:
The environment variable -> property map is manual - we need a property definition for every environment variable we want to pull in.
Specifying environment variables to Failsafe is again manual - we need a variable definition for every environment variable we want to pass on.
Right now, if we have 20 environment variables, we have 20 lines for each of these stages, and that's getting tedious quickly.
Is there a better way to do this?
My naive thoughts include (though I can't find a way to achieve it):
Define Maven properties dynamically, potentially based on a regex, from environment variables.
From Maven properties, automatically construct a list of environment variables, to be passed to Failsafe, again preferably via a regex.
Related
I'm trying to figure out how to make the build work in TeamCity. One of the problems is that I cannot get the correct version. In General settings tab, I have a build counter which works well (it increments every time I run a build). However:
If I don't define build.vcs.number in Parameters, TeamCity shows it anyway, marking that the value is required, and the parameter is undeletable.
If I define build.vcs.number and set the value to an empty string, I end up with the version 1.0.0.. If I set it to any value, such as 123, the version would be 1.0.0.123.
If I define build.vcs.number to be %build.vcs.number%, like in the third screenshot in a similar question, it seems that the parameter just references itself, and TeamCity doesn't know what to do in this case, and I get 1.0.0.???.
So how do I point build.vcs.number to the counter I see in General settings?
build.vcs.number is specific to your VCS. The build counter is build.counter. You shouldn't have to define them as build parameters. What are you trying to use the value for?
In device/vendor/rules.mk we have couples of flags. For example:
INCLUDE_VENDOR_PACKAGES:=true
I am writing a go package to do some conditional operation based on above flag. I tried couples of ways to fetch this flag's value such as via Golang's os package API and via $ operator like we do in shell script. But none of these worked.
Is there anyway to fetch the flag from Makefile at build time in go packages?
Make variables are internal to make.* They are not (directly) exposed to the recipes running in rules (or to commands run by GNU function implementations). You need to make explicit provision for feeding these values to commands that make runs, generally either by explicitly placing the wanted values into individual commands' environments or by passing them as command-line arguments to those commands.
* However, one place that make obtains variable values is from like-named environment variables, which will also be available under some circumstances to commands that make runs in turn.
What does % mean in windows environmental variables ?
%SystemRoot%\system32;
%SystemRoot%;
%SystemRoot%\System32\Wbem;
Especially the Path, TMP, TEMP variable values have this sign. There might be other variables also, but I came across only these three.
Do I need to bother about it while setting my own path variables ?
Do I need to bother about it while setting my own path variables ?
Under normal circumstances, no, you don't. You would only do this if you wanted the effective value of PATH to depend on some other environment variable. Even then it is only a convenience, never a necessity.
As a real-world example of when it might be convenient, suppose you've written a program that automates updating the Java SDK to the latest version, so your users don't have to do it by hand. Updating the SDK moves it to a different location, so you probably want to add the new location of the SDK to the path, and remove the old one.
You could do that the hard way, by parsing PATH each time, locating the part that points to the old location and changing it appropriately. But that's a pain, and if you're doing this globally, the users don't have any choice over whether Java is in the path, even if they don't use it. So instead you might create a variable JAVA_PATH that points to the current SDK location. That way, it is easy to change, and individual users can choose whether or not to put %JAVA_PATH% in their own paths.
In Microsoft's case (the examples you noticed) the system root is never going to move, but by using a variable they could hard-code the default value of PATH rather than having to explicitly generate it during operating system installation.
PS: the environment variables referenced in PATH must all be system variables. Referencing a user variable will not work.
%VariableName% is the syntax for referencing an environment variable. The actual name is the part between the % symbols.
So your first line, when fully expanded, would evaluate to the value of the SystemRoot variable, followed by \system32;.
You'll need to use %...% if you want to make use of environment variables in the Windows shell, or if you want to define environment variables that reference other variables.
Where I can get the full list of variables, replaced by the WinAPI function?
MSDN contains only a single example: %USERPROFILE%.
Is this list full and correct? http://www.rapidee.com/en/environment-variables
Call GetEnvironmentStrings to find out the environment for your process, at the point when you make the call. You will need to parse the double null-terminated string that is returned to find the name/value pairs.
Note that there is no single definitive list of environment variables. Each process maintains its own private environment. The environment is specified when the process is created. Typically it inherits from the environment of the parent process. But not always. It is perfectly possible, and normal, for the parent process to specify an environment for the child process that differs from its own.
Note also that the environment can change during the lifetime of the process. Calls made to SetEnvironmentVariable will modify the environment of the calling process.
You should be able to deduce by now that the list of variables in your link may or may not be found in an environment. An environment could contain all of those variables, or none of them. It could contain variables not found in that list. It could contain no variables at all.
Learn more about environment variables here: Environment Variables (MSDN).
I have a project with the same code base for different targets, which need different values for some variables. What is the best way to achieve that? Here are my thoughts:
Use a different property list resource containing the values for each target. Con: I have to parse the property list at runtime to get the values. The values appear in clear if someone looks inside the application bundle.
Use #defines in different include files. Con: For each new target, I have to use macro conditionals to include the correct file in the implementation.
Use a different implementation file for each target:
with constant global variables. Con: The namespace is polluted by these global variables.
with a class whose properties are the variables. Con: Each implementation has to rewrite the glue code for the properties.
Does anyone has a good solution? Or is better to factor the common code base into a library and use different projects each time?