KB0039 - Environments Disappear if Clicking Cancel within Git Manual Edit Mode

KB0039 - Environments Disappear if Clicking Cancel within Git Manual Edit Mode

Purpose

The purpose of this article is to outline an issue and workaround that is present in version 4.0.6 and 3.9.12 and earlier of PowerShell Universal. 

Issue

When PowerShell Universal has git sync enabled in manual edit mode, it's possible to cause the environments to disappear within the environment. The result is that scripts, APIs and dashboards fail to run because no environments are defined. 
This can be caused by doing the following: 
1. Ensure that you do not have a .universal\environments.ps1 file
1. Click Edit in the navigation bar
2. Click Cancel in the navigation bar
After this process, the environments page under Settings \ Environments will be empty. 

Root Cause

The root cause is a logic error in the PowerShell Universal configuration system causing the environments to be removed when the environments.ps1 file is not present. 

Work Around

Workaround 1

Restarting the PowerShell Universal service will force the discovery of environments and they will be created. 

Workaround 2

Ensuring an environments.ps1 file is created will prevent this issue from occurring. You can create a file by editing the environments with Settings\ Environments. 
Click the properties of one of the environments and edit one of the values (such as max runspaces) and click ok. After doing so an environments.ps1 file will be created. From there, you can click View Changes and then commit your changes to git. The issue will no longer be present.