Welcome to the Inedo Forums! Check out the Forums Guide for help getting started.
If you are experiencing any issues with the forum software, please visit the Contact Form on our website and let us know!
How to update a buildmaster variable from a custom action
-
I simply want to simulate what the built-in extension "Set Variable Value" does in my custom action. I've tried with all the variable scopes (Execution, Release and Build)
I've tried 2 methods:
- this.Context.Variables["myVar"] = "The new value"; --> This actually updated the value in the DB, but is not reflected in Buildmaster once a new action is started.
- StoredProcs.Executions_SetVariableValue(this.Context.ExecutionPlanActionId, "myVar", "The new value"); --> This has no effect whatsoever.
My custom action is a RemoteActionBase.
How is this 'Set Variable Value' performs the value update?
Product: BuildMaster
Version: 4.8.6
-
Here is the v4.9.6 source for that action as a reference (should work as is for v4.8.6 as well): http://44.inedo.com/buildmaster/sources/SetVariableAction.zip
There are some caveats to variable setting because it is inherently complicated, as it can rely on data from external servers, there is cascading to consider, whether it should replace an existing variable's value, whether it should create a new variable with the same or different value that overrides only for a single execution, etc.
If you could describe exactly what you are you trying to do with regards with variable setting, we can provide better guidance.
In the meantime, the API method you want is:
StoredProcs.Variables_CreateOrUpdateVariableDefinition( string Variable_Name, int? Environment_Id, int? Server_Id, int? ApplicationGroup_Id, int? Application_Id, int? Deployable_Id, string Release_Number, string Build_Number, int? Execution_Id, string Value_Text, string Sensitive_Indicator ).Execute();
Supplying combinations of the various IDs/Numbers is the "context" of the variable, i.e. to modify a build variable value, you must supply
Application_Id
,Release_Number
, andBuild_Number
(with the others beingnull
). To create/update an execution variable, onlyExecution_Id
should be passed in.Note that for
RemoteActionBase
, you cannot call thisStoredProcs
method from theProcessRemoteCommand()
method, it must be done inExecute()
. If the value is captured from a remote server, just return the variable value as a string fromProcessRemoteCommand()
and then call theStoredProcs
method fromExecute()
.Simplified example of
RemoteActionBase
:protected override void Execute() { string value = this.ExecuteRemoteCommand(string.Empty); // call StoredProcs.Variables_CreateOrUpdateVariableDefinition here... } protected internal override string ProcessRemoteCommand(string name, string[] args) { // this method runs on the remote server... string value; // get value from somewhere... return value; }
-
Tod,
Thanks very much for this piece of info and the source. Very useful. I've been able to do complete my extension, working all good!