Build variables

I have a question about build variables and VariableNamespaces.xml.
I update build variables via print @@continua setVariable with or without updateBuildVariable build variables are updated in build.
When is VariableNamespaces.xml updated ? I want to update variable from one script and read updated value from second script, is that possible ?

I see that updateBuildVariable is used only when setting server variable.
But still from my tests it seem that XML is updated after stage start → so it continas variables set at start, also user provided and then it’s updated at the end with current values of build variables.
During runtine no updates are done.

You need to use a Build Event handler to persist variables between stages.

It’s a bit heavy handed, perhaps we can look at making it simpler in the future.

what about storing it between actions ? :smiley:
python script → updates variables
python script → reads updated values

Hi Michal,

The setBuildVariable custom log message can be used to set the value of a build variable in the first script action. The build variable can then be passed to the subsequent action via arguments or environment variables.

VariableNamespaces.xml is used internally by Continua for transferring build variables between stages. It’s not really there to use with your own scripts.

The Persist Build Variables build event handler is for updating the variable on the server so that it can be used by other builds. It’s not required for transferring build variables between stages as this is done automatically.

The setServerVariable custom log message is also for updating the variable on the server so that it can be used by other builds. The updateBuildVariable argument ensures that the build variable is also updated when the server variable is set.

1 Like

But this XML can be at least used to get input variables (base values and values provided when starting the build, checkboxes etc.), am I right ?
I have a bunch that I would very much would like not to pass as arguments → more than 10 :smiley:

Hi Michal,

Yes, you can read input values from VariableNamespaces.xml with the caveat that it is only set at the start of the first stage and updated at the end of each stage.

Note that you can also use the “Generate system environment variables” option to automatically set environment variables for every build variable. This is available to most actions including the Python action. You can then read the environment in your python script e.g. variableAValue = os.environ.get('ContinuaCI.VariableA').

Some actions (Execute Program, Run DOS Command / Batch File, PowerShell and FinalBuilder) also have a “Generate a context XML file” option which writes all the current variables, properties etc. to an XML file before executing the action. We can possibly add this option to the Python action if it is useful.

Thank you for the reply and describing how this works. No I don’t think this is needed for Python action.
What I really wanted was the input variables (we have a lot of checkboxes for delivery configuration) and was wondering if this file could be the database for my variables, but that’s OK, I just create my own json file and I’m good.