Toolboxcategory cloud |
ViewsPersonal toolsUsing Environment Variables With ScriptsFrom Seapine LabsSurround SCM gives users the option to set up triggers. These triggers can be used to send emails when certain events occur, prevent certain actions from occurring or to run a script. This article focuses on the use of scripts. Specifically, this article focuses on how to get Surround SCM environment variables dynamically when the script is run by the trigger. Surround SCM environment variables offer a great way to get information at run-time for scripts used with triggers. Instead of creating multiple scripts with hard coded Surround SCM information, only a few scripts need to be created using the environment variables.
The following table includes the available Surround SCM version 5 system variables. This is just meant to be used as a quick reference. It is recommended that you first read the user guide section on environment variables.
Table 1 - Surround SCM Environment Variables
These environment variables are especially useful to get information that is only available when the script runs. [edit] DOS ExampleAn administrator wants to keep track of files that are renamed in a specific branch in Surround SCM. The administrator creates a batch file with the following content:
The administrator saves the file and names it "base.bat" and then creates the following trigger:
Note: The path of the script file is on C:\ drive of the computer where the Surround SCM Server is running, not the computer where the Surround SCM client is running. A user later takes the file named "test.cpp" and renames it to "testing.cpp". The output file ("testfile.txt") has the following content after the trigger runs the batch file:
Note: The path of the output file is also the C:\ drive on the computer the Surround SCM Server is running on, not the computer the Surround SCM client is running on. [edit] C# ExampleYou can also get Surround SCM variables using a programming language. C# can get any system variable by using:
So you can retrieve the file name that triggered the script like this:
The following example copies a file before it is checked in:
//First we check to make sure there are environment variables
if ((!(System.Environment.GetEnvironmentVariable("SSCM_LOCALFILE") == null))&&(!(System.Environment.GetEnvironmentVariable("SSCM_FILE") == null)))
{
surroundLocalFile = System.Environment.GetEnvironmentVariable("SSCM_LOCALFILE");
surroundFileName = System.Environment.GetEnvironmentVariable("SSCM_FILE");
FileInfo scmFile = new FileInfo(surroundLocalFile);//File that surround is about to check in
FileInfo copyFile = new FileInfo(@"d:\" + surroundFileName);//destination and file name of copy
//if the file already exists in the destination location, delete it.
if (copyFile.Exists)
{
copyFile.Delete();
}
scmFile.CopyTo(@"d:\" + surroundFileName);
}
One thing to note is that the "SSCM_LOCALFILE" variable does not return the file in the working directory about to be checked in. It returns the .tmp file that Surround actually uses for the check in. This is why we need to get the "SSCM_FILE", so we can use it as file name for the copy. [edit] C++ ExampleSeveral examples of how to use Surround SCM environment variables using C++ are available from the Surround SCM add-ons page: http://www.seapine.com/scmresources.php#trigger Following is one line of code that illustrates how to get a Surround SCM environment variable using C++:
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||


