Inedo Community Forums Forums
    • Recent
    • Tags
    • Popular
    • Login

    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

    Scheduled Pinned Locked Moved Support
    variablesbuildmaster
    3 Posts 1 Posters 8 Views
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • ? This user is from outside of this forum
      Guest
      last edited by

      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:

      1. 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.
      2. 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

      1 Reply Last reply Reply Quote 0
      • ? This user is from outside of this forum
        Guest
        last edited by

        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, and Build_Number (with the others being null). To create/update an execution variable, only Execution_Id should be passed in.

        Note that for RemoteActionBase, you cannot call this StoredProcs method from the ProcessRemoteCommand() method, it must be done in Execute(). If the value is captured from a remote server, just return the variable value as a string from ProcessRemoteCommand() and then call the StoredProcs method from Execute().

        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;
        }
        
        1 Reply Last reply Reply Quote 0
        • ? This user is from outside of this forum
          Guest
          last edited by

          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!

          1 Reply Last reply Reply Quote 0

          Hello! It looks like you're interested in this conversation, but you don't have an account yet.

          Getting fed up of having to scroll through the same posts each visit? When you register for an account, you'll always come back to exactly where you were before, and choose to be notified of new replies (either via email, or push notification). You'll also be able to save bookmarks and upvote posts to show your appreciation to other community members.

          With your input, this post could be even better 💗

          Register Login
          • 1 / 1
          • First post
            Last post
          Inedo Website Home • Support Home • Code of Conduct • Forums Guide • Documentation