Walkthrough: Managing versions of NSH scripts using Git
This topic walks you through the use of Git for version management of NSH scripts. It includes the following sections:
- Introduction
- What does this walkthrough show?
- What do I need to do before I get started?
- How to migrate existing NSH scripts to the local repository
- How to save a new script and commit it into the local Git repository
- How to commit changes to a script
- How to compare script revisions and revert to a previous revision
- How to push all changes to the remote Git repository
- Wrapping it up
The video at right demonstrates the various tasks involved in version management of NSH scripts using Git.
Introduction
This topic is intended for system administrators or operators who are responsible for the creation, modification, and use of NSH scripts in TrueSight Server Automation.
The goal of this topic is to use an integration with Git for version management tasks, such as keeping track of revisions, comparing revisions, or reverting to an earlier revision .
What does this walkthrough show?
This walkthrough shows how to use Git for version management of NSH scripts. The walkthrough includes the following tasks:
- Migrating existing NSH scripts to a local repository.
- Choosing the option for storage in the local Git repository while adding a new NSH script to the depot.
- Committing revisions of an NSH script to the local repository.
- Reviewing a history of revisions in an NSH script, including information regarding who made each change and when.
- Comparing revisions of an NSH script.
- Reverting to an earlier version of an NSH script.
- Pushing all committed revisions of an NSH script to the remote Git repository.
What do I need to do before I get started?
Before you can manage versions of NSH scripts, ensure that you have set up a local repository in the TrueSight Server Automation environment, as well as the remote Git repository. For more information about these setup tasks, see Setting-up-Git-repositories.
For this walkthrough, we have logged on as BLAdmin, the default superuser for BSA.
How to migrate existing NSH scripts to the local repository
In this example, TrueSight Server Automation was only recently integrated with a Git repository, and many NSH scripts in the depot were created prior to the integration. These NSH scripts were saved in the file server, rather than the local Git repository, and do not support version management. To enable version management for such NSH scripts, you can migrate them from the file server to the local Git repository either individually or in bulk. First let's move one NSH script to the repository and examine how this migration changes script settings.
Step | Example screen | |
---|---|---|
1 | Under the Depot folder, navigate to an NSH script that was created some time ago (before you set up the Git integration), and open it. | |
2 | In the open NSH script, note that only 3 tabs are displayed (Script Options, Script, and Parameters). In addition, on the Script Options tab, note that the Repository Type field is set to BSA Repository and is not editable. Now close the NSH script. | |
3 | Right-click the NSH script again in the tree, and choose Move to Git. | |
4 | In the confirmation message, click Yes. | |
5 | Now, when you open the NSH script, the Repository Type field on the Script Options tab is set to Git Repository (still not editable). In addition, a fourth tab is displayed, Git Repository History. On this tab, you see that the NSH script was immediately committed to the local Git repository, with the message "Migration to Git from Fileserver - First Commit..." |
Now let's move multiple NSH scripts to the repository, all at once, through the Group Explorer view.
Step | Example screen | |
---|---|---|
1 | From the main menu, select Window > Show View > Group Explorer. | |
2 | Under the Depot folder, click a folder that contains multiple unmigrated NSH scripts. | |
3 | Select multiple unmigrated NSH scripts, right-click, and choose Move to Git. | |
4 | In the confirmation message, click Yes. | |
5 | The Git-Migration-Result-dialog-box displays the results of the migration. |
How to save a new script and commit it into the local Git repository
In this example, we will add an NSH script to the depot and set it to be saved in the local Git repository (rather than in the file server), so that we can control the versions of this NSH script in the future. We will then commit the initial version of the script to the local Git repository.
Step | Example screen | |
---|---|---|
1 | Under the Depot folder, right-click the folder in which you want to store the NSH script, and select New > NSH Script. |
|
2 | In the Add NSH Script to Depot wizard (on the Script Options panel), enter a name for the script in the Name field, and specify the location of the script in the File Location field. Then, in the Repository Type field, select Git Repository (this is the default option). Finally, click Finish. The NSH script is added to the folder. You might need to refresh the folder to see the newly added script. | |
3 | Navigate to the newly added NSH script, right-click it, and select Open. | |
4 | Click the Git Repository History tab. The list of script revisions contains one entry with the commit message "Uncommitted changes exist." | |
5 | Click the Commit button | |
6 | In the Git Commit dialog box, adjust the email address and enter a summary message to accompany the commit. Afterwards, click Commit and then click OK in the informational message. | |
7 | Take another look at the list on the Git Repository History tab. The initial entry now has commit details. |
How to commit changes to a script
The example script that we just added to the depot collects various statistics from a target server's operating system and generates a report on a reporting server. However, the IP address of the reporting server is hard-coded within the script. We will now edit this IP address, to switch to a different reporting server. We will also add a new script parameter named TEST. We will then commit the change to the local Git repository.
Step | Example screen | |
---|---|---|
1 | In the open script, click the Script tab. Then make a change within the script text. In this example, we will set new values for the REPORTS_SERVER and REPORTS_DIR parameters. After editing the script text, save the NSH script using the Save button | |
2 | Click the Parameters tab. To add a new parameter to the script, click the Add Parameter Remember to save the NSH script using the Save button | |
3 | Click the Git Repository History tab. A new entry appears in the list of script revisions, with the commit message "Uncommitted changes exist." | |
4 | Click the Commit button | |
5 | In the Git Commit dialog box, adjust the email address and enter a summary message to accompany the commit. Afterwards, click Commit and then click OK in the informational message. Commit details for the new revision are added on the Git Repository History tab. |
How to compare script revisions and revert to a previous revision
The list of changes in the script contains already two entries. We will compare the two versions and revert to the earlier version of the script.
Step | Example screen | |
---|---|---|
1 | In the open script, on the Git Repository History tab, review the various entries listed in the history of script changes. Each entry provides commit details, including the commit message, the name of the user who made the change, and the date and time when the change was made. | |
2 | Select the two script revisions and click Compare | |
3 | Two new tabs appear in the editor — one with a comparison of the script contents and the other with a comparison of the script parameters (in json format). On each tab, the comparison opens directly to the first difference between the two versions. The newer version is on the left and the older version on the right. To navigate to other differences, use the Next Change | |
4 | After reviewing the differences, we have decided to revert to the original version of the script. To revert, return to the open script, select the version of the script to which you want to revert, and click Get This Revision | |
5 | In the confirmation message, click Yes. | |
6 | A new change entry is added to the script history. To finish reverting to the earlier version of the script, you must commit this change. Click Commit | |
7 | In the Git Commit dialog box, adjust the email address and enter a summary message to accompany the commit for the revert. Afterwards, click Commit and then click OK in the informational message. | |
8 | Commit details for the new revision are added on the Git Repository History tab. |
How to push all changes to the remote Git repository
You must periodically push all changes stored in the local Git repository to the remote Git repository.
Step | Example screen | |
---|---|---|
1 | In the console, click the Push button | |
2 | The Git-Push-dialog-box displays information about all commits that will be pushed to the remote Git repository. Click Push. | |
3 | Click OK in the informational message. |
Wrapping it up
Congratulations! You have successfully performed version management on an NSH script.
Now that you are actively managing changes in NSH scripts, you can choose any previous version of a script to associate with a Network Shell Script Job, during creation or modification of the Network Shell Script Job.