Registering a new version of a multi-artifact DataMiner package to the Catalog using Visual Studio and GitHub
In this tutorial, you will learn how to develop, (pre-)release, and upload a DataMiner package to the Catalog with a basic CI/CD pipeline using Visual Studio and GitHub. This package will contain multiple artifacts:
- Automation script: TutorialScript1
- Automation script: TutorialScript2
- Automation script library: TutorialLibrary
- Ad hoc data source: TutorialDataSource
The package will include a simple .txt file that will be read out during installation, generating an information event with the information from the file.
Expected duration: 15 minutes
Prerequisites
- A GitHub account
- DataMiner Integration Studio
- Microsoft Visual Studio 2022
- An organization key or system key or account with the Owner role in order to access/create keys.
Overview
- Step 1: Add code-based content
- Step 2: Add installation-specific code
- Step 3: Create a GitHub repository
- Step 4: Check the GitHub Actions
- Step 5: Create and add a secret
- Step 6: Check the results
Step 1: Add code-based content
Start by adding all code-based content into a Visual Studio solution:
Create a DataMiner package project:
Open Visual Studio, and select Create a new project.
Select the DataMiner Package Project template, and click Next.
Enter the project name
TutorialPackage.Make sure Place solution and project in the same directory is not selected, and click Next.
Fill in your name as the author and keep Create DataMiner Package selected.
Under Add GitHub CI/CD Workflow (Overwrite Existing), select Demo.
Click Create.
Add a first DataMiner automation script project:
In the Solution Explorer, at the very top, right-click the solution TutorialPackage and select Add > new project.
Select the DataMiner Automation Script Project template, and click Next.
Enter the project name
TutorialScript1.Fill in your name as the author and make sure Create DataMiner Package is not selected.
Under Add GitHub CI/CD Workflow (Overwrite Existing), keep the default None selected.
Click Create.
Add a second DataMiner automation script project:
In the Solution Explorer, at the very top, right-click the solution TutorialPackage and select Add > new project.
Select the DataMiner Automation Script Project template, and click Next.
Enter the project name
TutorialScript2.Fill in your name as the author.
Click Create.
Add a DataMiner automation script library project:
In the Solution Explorer, at the very top, right-click the solution TutorialPackage and select Add > new project.
Select the DataMiner Automation Script Library Project template, and click Next.
Enter the project name
TutorialLibrary.Fill in your name as the author.
Click Create.
Add a DataMiner ad hoc data source project:
In the Solution Explorer, at the very top, right-click the solution TutorialPackage and select Add > new project.
Select the DataMiner Ad Hoc Data Source Project template, and click Next.
Enter the project name
TutorialDataSource.Fill in your name as the author.
Click Create.
Step 2: Add installation-specific code
In this step, you will focus on the extra code that should be executed when the content is installed.
Add the setup content:
In the Solution Explorer, navigate to the project TutorialPackage and right-click the SetupContent folder.
Select Add > New Item.
Select to add a new text file (.txt), and give it the name
MyConfig.txt.Write
Hello World!as the content and save the file.
Write the installation code:
In the Solution Explorer, navigate to the project TutorialPackage and double-click to open the TutorialPackage.cs file.
Change the content of the Install method to the following:
try { engine.Timeout = new TimeSpan(0, 10, 0); engine.GenerateInformation("Starting installation"); var installer = new AppInstaller(Engine.SLNetRaw, context); installer.InstallDefaultContent(); string setupContentPath = installer.GetSetupContentDirectory(); // Custom installation logic can be added here for each individual install package. string pathToConfig = System.IO.Path.Combine(setupContentPath, "MyConfig.txt"); var config = System.IO.File.ReadAllText(pathToConfig); engine.GenerateInformation($"Tutorial installation ran with config: {config}"); } catch (Exception e) { engine.ExitFail($"Exception encountered during installation: {e}"); }Save the changes
Step 3: Create a GitHub repository
In the menu bar of Visual Studio, select GIT > Create GIT Repository.
Create a new GitHub repository:
Select a name, specify your GitHub account, and mark yourself as the owner.
When you have entered all the information, click Create and Push.
Go to the newly created GitHub repository on https://github.com/.
Tip
In Visual Studio 2022, you can open the GIT menu and select GitHub/View Pull Requests to quickly access the correct repository.
Step 4: Check the GitHub Actions
In GitHub, go to the Actions tab.
Click the workflow run that failed (usually called Add project files).
Click the "build" step that failed and read the failing error.
Error: DATAMINER_TOKEN is not set. Release not possible! Please create or re-use an admin.dataminer.services token by visiting: https://admin.dataminer.services/. Navigate to the right organization, then go to Keys and create or find a key with the permissions Register catalog items, Download catalog versions, and Read catalog items. Copy the value of the token. Then set a DATAMINER_TOKEN secret in your repository settings: <Dynamic Link>You can use the links from the actual error in the next couple of steps.
Step 5: Create and add a secret
Obtain an organization key from admin.dataminer.services with the required scopes:
- Register catalog items
- Read catalog items
- Download catalog versions
Tip
See also: dataminer.services keys
Add the key as a secret in your GitHub repository, by navigating to Settings > Secrets and variables > Actions and creating a secret named
DATAMINER_TOKEN.Re-run the workflow.
With this setup, any push with new content (including the initial creation) to the main/master branch will generate a new pre-release version, using the latest commit message as the version description.
Step 6: Check the results
Go to the Catalog
Check in the upper-right corner if the correct organization is selected.
Search for the name of your package.
By default, this is your Visual Studio project name (e.g., TutorialPackage).
Go to the VERSIONS tab.
This tab should contain the new version of the package, which is now available for deployment from the Catalog.
If you have an available non-production DataMiner Agent, use the Deploy button to deploy the new version to the DMA.
All artifacts will be installed. In DataMiner Cube, you should see an information event in the Alarm Console saying Tutorial installation ran with config: Hello World!.