Important

   

This space contains documentation for TrueSight Server Automation 8.9.03 and the later service packs for 8.9. For earlier releases, see BMC Server Automation 8.9.

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:

The video at right demonstrates the various tasks involved in version management of NSH scripts using Git.

  https://youtu.be/lW7fHYMJnBM

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.

Note

To perform this migration task through the BLCLI (as an alternative to the GUI method described here), you can use the NSHScript moveToGit command.

 StepExample 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.

3Right-click the NSH script again in the tree, and choose Move to Git.

4In 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.

 StepExample screen
1

From the main menu, select Window > Show View > Group Explorer.

2Under the Depot folder, click a folder that contains multiple unmigrated NSH scripts.
The contents of the folder appear in the Group Explorer view.

3 Select multiple unmigrated NSH scripts, right-click, and choose Move to Git.
4In the confirmation message, click Yes.
5The Git Migration Result dialog box displays the results of the migration.
Ensure that all items were migrated successfully.

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.

Note

To perform this task through the BLCLI (as an alternative to the GUI method described here), you can use the NSHScript addNSHScriptToExternalRepo command followed by the NSHScript commitNSHScript command. You use the addNSHScriptToExternalRepo command when you want to enable version management for a new NSH script, as opposed to the addNSHScriptToDepotByGroupName command, which you use when you do not want to enable version management.

 StepExample screen
1Under 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).

Note

If you choose the BSA repository option while adding the NSH script to the depot, the only way to subsequently switch to the Git Repository option and enable version management for the NSH script is to migrate the NSH script to the Git repository.

Finally, click Finish.

The NSH script is added to the folder. You might need to refresh the folder to see the newly added script.

3Navigate 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."

5Click the Commit button  above the list.
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.

7Take 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.

Note

To perform the commit task through the BLCLI (as an alternative to the GUI method described here), you can use the NSHScript commitNSHScript command. 

After upgrading to TrueSight Server Automation 8.9, various issues might arise in the Git version management of existing, pre-upgrade NSH scripts. To avoid such issues, perform an initial commit of each existing NSH script before performing any further actions on the script (such as changing script parameters or reverting to an earlier revision). For this initial commit action, use the following steps:

  1. Make a small change in the script text. This change can be any dummy edit, such as adding a comment line.
  2. Commit the script, as described below.
 StepExample 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  in the toolbar.

2

Click the Parameters tab. To add a new parameter to the script, click the Add Parameter  icon, and then, in the Add Parameter dialog box, enter a name for the parameter (in this example, we named the parameter TEST), and click OK.

Remember to save the NSH script using the Save button  in the toolbar.

3

Click the Git Repository History tab.

A new entry appears in the list of script revisions, with the commit message "Uncommitted changes exist."

Note

If this commit message does not appear (typically, after a product upgrade, due to upgrade issues), click the Refresh button  above the list.

4Click the Commit button  above the list.
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.

 StepExample 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  and Previous Change  buttons above the compared text.

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 .

5In the confirmation message, click Yes.
6A 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.

8Commit details for the new revision are added on the Git Repository History tab.

Note

Any versions of the NSH script that were committed to the repository before upgrading to TrueSight Server Automation 8.9 will not have parameter information stored. For such script versions, a comparison of parameters is not generated. Similarly, when reverting to such a version of the script, the parameters are not reverted.


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.

Note

 To perform this task through the BLCLI (as an alternative to the GUI method described here), you can use the Git pushToRemote command.

 StepExample screen
1

In the console, click the Push button in the toolbar.

2

The Git Push dialog box displays information about all commits that will be pushed to the remote Git repository.

Click Push.

3Click 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.


Was this page helpful? Yes No Submitting... Thank you

Comments