[K2 Package and Deployment] — Deploy with PowerShell

  • 23 July 2019
  • 0 replies
  • 203 views

Original post come from my blog here: https://medium.com/k2-dev-en/k2-package-and-deployment-deploy-with-powershell-47245843b2d0

 

I’ve a question from customer few days agos about deploy K2 package with script. If you see in official guide (https://help.k2.com/onlinehelp/k2five/userguide/5.3/default.htm#PackageAndDeploy/Powershell-Automated-Deployment.html%3FTocPath%3DCreate%7CDeploying%2520K2%2520applications%7CDeploying%2520a%2520Package%7C_____5), you will find some instructions but not too detail. So in this blog I’ll provide step by step to deploy package using script (PowerShell)

 

Create Package

Before we deploy, we need to create package. The package I use was Form, View, SmartObject and Workflow using Service Instance that connect to SQL database. All objects as below.

 

                                                              Object in package

 

Create Deployment Configuration File

After we got package file, we need to open Windows PowerShell.

                                                       Open Windows PowerShell

 

Input below command to add package and deployment snapin to PowerShell.

add-pssnapin SourceCode.Deployment.PowerShell

                                               Run Add PowerShell Snapin

 

Using below command to generate XML Configuration File for our package. Recommend to use same file name as our package name.

Write-DeploymentConfig ‘{Path}Package Name.kspx’ -OutputFile ‘{Path}Package Name.xml’

                                                Run to Create XML Configuration File

 

Open Configuration File to see the default setting

 

                                                Configuration File

 

Section that we focus is SpecificOptions tag. Under this tag is the list of object that we have in package. Action that we can use as below

  • Default => Use default action that package and deployment analyst for us
  • Deploy => Deploy this object
  • Exclude => Not deploy this object
  • UseExisting => Use object that exist on target environment. We always use this option with Service Instance.

In general, we don’t need to change configuration that package deployment tool generate for us. If we use Default, package and deployment will automatically select appropriate action for us. We’ll change to Deploy option in case that we want to make sure that object will deployed to target environment.

 

Deploy Package

Before we deploy, we need to check object that not include in package and deployment tool. List of objects as below (reference: https://help.k2.com/onlinehelp/k2five/userguide/5.3/default.htm#PackageAndDeploy/PandD-Considerations.htm%3FTocPath%3DCreate%7CDeploying%2520K2%2520applications%7C_____4)

  • SharePoint objects (list, libraries, field, columns, content types and items in list or libraries)
  • Database and object in database (table, view, stored procedure)
  • Web services or dll that we need to reference
  • Custom configuration in file configure (K2HostServer.exe.config)
  • Service Instance

After we already checked, we’ll proceed to deployment. Before we deploy, I’ve delete the object that I already packed so we can check that our deployment was success. Command to deploy will be

Deploy-Package -FileName ‘{Path}Package Name.kspx’ -ConfigFile ‘{Path}Package Name.XML’

                                                           Successful Deployment

 

After deploy, we need to check the result and it was successful.

 

                                                                     Check Result

 

Deploy with Different Service Instance Name

In real word, sometimes we create Service Instance with different name in different environment. If we deploy using UI, we have option to select existing Service Instance. In command, we’ve the same functionality.

 

                                                Different Service Instance Name

 

In my example, I create SmartObject reference with EmployeeOnboarding Service Instance. But in target environment, we create Service Instance as NewEmployeeOnboarding.

What we have to add in Configuration File is adding tag targetName to specify new service instance name and targetNamespace to specify namespace of new service instance. In fact, targetNamespace was the same as our old service instance, but we need to add in otherwise we’ll got error when deploy.

So I we want to change EmployeeOnboarding to NewEmployeeOnboarding we need to add tag as below

<resolve name=”EmployeeOnboarding” namespace=”urn:SourceCode/SmartObjects/ServiceInstance” action=”UseExisting” targetName=”NewEmployeeOnboarding”
targetNamespace=”urn:SourceCode/SmartObjects/ServiceInstance”
/>

                                                Change Service Instance Name

 

After modify Configuration File, we deploy again (and yes!!! I delete object before deploy again). When command run success, we’ll check our SmartObject and it change to use our new Service Instance.

 

                                                        SMO Use New Service Instance

 

Summary

When we want to deploy package to another environment, what we need to do is deployment guide. Deployment with PowerShell will reduce time that we used to create deployment guide. If our organization using automate deployment tools, we can adapt PowerShell command with a tool. Our life would be a little bit easier. It’s all for this time :)


0 replies

Be the first to reply!

Reply