The PowerShell Snap-in can be used to automate the deployment of single or multiple artifact packages from source environments to target environments without the need for user intervention. This may be especially useful where it is necessary to make regular or frequent package deployments, or where script-based installations and updates might be preferred. The PowerShell Snap-in functionality cannot be used to create deployment packages, but only to deploy them. Package creation can only be done through the K2 Package and Deployment interface.
PowerShell package deployments utilize Namespaces. For a detailed explanation, please refer to the Important Considerations section below.
Microsoft Management Console (MMC) 3.0 or later, and Microsoft PowerShell 3.0 or later are prerequisites for K2 Package and Deployment. MMC 3.0 and PowerShell 3.0 are components of the Windows Management Framework 3.0 package, which can be downloaded from http://www.microsoft.com/en-us/download/details.aspx?id=34595.
The following quick steps outline how PowerShell deployment is typically used:
When copying code from this help file to the PowerShell interface, make sure there are no unwanted line breaks in the code text.
#Adds the PowerShell Deployment snapin.
add-pssnapin SourceCode.Deployment.PowerShell
#Scripts the sample XML configuration file to be used for deployment.
Write-DeploymentConfig 'C:\Users\Dewald\Desktop\Perf Packages\RTM\Package3.kspx' 'C:\Users\Dewald\Desktop\Perf Packages\RTM\Package3.xml'
-InputFile (where 'InputFile' is the *.KSPX (K2 Package) file to be deployed.)
-OutputFile (where 'OutputFile' is the corresponding *.XML configuration file which will be generated.)
An optional command is -ConnectionString (Connection string to K2 server, for example: “Host=LOCALHOST;Port=5555;Integrated=True;IsPrimaryLogin=True”. If no value is specified, known defaults will be used.)
The following configuration options are supported by the K2 PowerShell snap-in:
If needed, these options must be manually inserted into the *.XML configuration file. ServiceInstances and Environmental fields will always default to "UseExisting" and must manually be changed to "Deploy" or "Default". In context of the *.XML, each configuration option must be phrased as an action which is applied to a specific artifact. For example, if the UseExisting configuration command was applied to a 'From Address' namespace, the command might be expressed as follows:
<resolve name="From Address" namespace="urn:SourceCode/EnvironmentSettings/Fields" action="UseExisting" />
Note that in order for the UseExisting option to function, an item must already exist on the target environment to which the new item is being deployed. If the item being deployed has a different name to the existing item, the targetName and targetNamespace attributes of the existing item must be specified within the *.XML configuration file.
For example, where "GIVEN ITEM" is the given item, the following configuration option will deploy the item:
<resolve name="GIVEN ITEM" action="Deploy" namespace="urn:SourceCode/Files"/>
For more information on variables, refer to the 'Assigning Variables' sub-section of 'Creating a Package'.
A sample Deploy-Package command might be written as follows:
#Scripts the deployment of a package
Deploy-Package -FileName 'C:\TestPackage.kspx' -ConfigFile 'C\TestPackage.XML'
The K2 Deployment PowerShell Snap-in uses a combination of Namespace/Class structures and Name/Namespace structures to deploy the package to the target environment.
Service Instances use a Namespace/Class structure. All other packaged items use a Name/Namespace structure. Note that all Namespace/Class and Name/Namespace structures must be unique to the specific item being described.
As an example, Namespace/Class conditions for Service Instances must be taken into account as follows within the configuration *.XML file. (The %2E in this case represents a full stop [i.e. '.']):
#urn:SourceCode/SmartObjects/ServiceInstance
SourceCode%2ESmartObjects%2EServices%2ESQL%2EsqlServerService
The Package and Deployment namespace structure relates to namespace and class as defined within the code itself. For example, the code in the block above is not a reference to the Assembly Name, but rather to the Namespace and Class within the Assembly, which inherits properties from ServiceAssemblyBase. For the example above, the name of the Assembly is 'SourceCode.SmartObjects.Services.SqlServer.dll'. However, the namespace and class structure is as per the code block below:
namespace
SourceCode.SmartObjects.Services.SQL
{
public class SqlServerService : ServiceAssemblyBase
{
Some examples are as follows:
urn:SourceCode/Categories?AdventureWorks#Path.%2F represents a 'root' category called 'AdventureWorks'.
Thus, the output would be:
1. AdventureWorks
The representation above is explained as follows:
urn:SourceCode/Categories defines the namespace of the object.
?AdventureWorks defines the 'Instance name' of the object (In this case, a category called AdventureWorks (i.e. '/AdventureWorks/')).
#Path defines the object path. In this instance, the object path is 'blank', as AdventureWorks is the 'root' category.
%2F is the path-separator symbol, being URI code for the 'forward slash' used as a separator.
urn:SourceCode/Categories?Production#Path.%2FAdventureWorks %2F represents a sub-category under 'AdventureWorks' called 'Production'.
Thus, the output would be:
1. AdventureWorks
a. Production
The definitions are the same as for the first example. However, in this instance, Path.%2FadventureWorks%2F defines the object path (In this case, a category below 'AdventureWorks' called 'Production' (i.e. /AdventureWorks/Production/ )).
urn:SourceCode/Categories?Forms#Path.%2FAdventureWorks%2FProduction%2F represents a sub-category under 'AdventureWorks' and 'Production' called 'Forms'.
Thus, the output would be:
1. AdventureWorks
a. Production
i. Forms
The definitions are the same as for the first example. However, in this instance, Forms#Path.%2FAdventureWorks%2FProduction%2F defines the object path (in this case, a sub-category below 'AdventureWorks' and 'Production', called 'Forms', i.e. /AdventureWorks/Production/Forms/).
When PowerShell is used to make a deployment to a distributed environment, you will need to specify named parameters, including a connection string, in the following format: -FileName -ConfigFile -ConnectionString.
A sample command for deployments to distributed environments might be presented as follows:
Deploy-Package -FileName 'C:\GenericPackage.kspx' -ConfigFile 'C:\GenericPackage.XML' -ConnectionString 'Host=main.hostserver.local;Port=5555;Integrated=True; IsPrimaryLogin=True;SecurityLabelName=K2;UserID=User1; Password=mypassword;WindowsDomain=HOSTSERVER'
From K2 blackpearl 4.6.9 and following, to deploy a CRM Smart Object using PowerShell there must be an existing CRM service instance in the destination environment. The CRM Service Instance SystemName and GUID must also match the CRM service instance of the source environment. To specify that the service instance should use the existing service instance, update the Reference Options tag as follows:
<referenceOptions>
<rebind id="1727" name="CRM_Denallix" baseType="SourceCode.SmartObjects.CRM5Entity.CRMEntityService" action="UseExisting" targetName="CRM_Denallix" />
</referenceOptions>
By default, the deployment log file is saved to the same location as the package (*.KSPX) file used for the given deployment. Should any deployment errors occur and require troubleshooting, these errors will be recorded within the log file.
Video | Links | Learn | Support |
No videos found for this article K2 on YouTube
No Additional links found for this article
No self-learning content for this article Try some scenarios...
No relevant support links available for this article
|