How to: Qlik Application Automation for backing up and versioning QCS apps on Github
An integrated version control systems always have been among the frequent questions, often reported in RFx. The following article is going to show a step-by-step guide on how to set an Application Automation to push QCS apps, without data, to a github repository when they are published on a (production) space.
How to connect Qlik Application Automation Connectors
How to create a GitHub Repo
What we are going to achieve
We are going to create a github repository containing all the published apps organized in folders, where the folder name mirror the published space. Since spaces are used to manage the softwer lifecycle and the different environments (Develop, Test, Performance, Production), we wants only applications published to the production spaces get saved and versioned on the github repository.
Set the Qlik Sense Enterprise SaaS environment
First of all, since we don't want push every published application up to the git repo, we have to define the production spaces. In this guide we explicitly use the word "Production" in the space description.
From within a space, click the cog icon on the top right corner and select Edit space
Space setting options
In the Edit Space dialog window make sure to add the word Production in the description.
Edit Space Dialog window
Create a new github repository, it can be private or public. In either way the Github connector needs to be authenticated with write permission.
From your tenant web hub, click on Add new --> New Automation. Give it a name and description, optionally select the more appropiate icons, then click Save.
Create New Automation
The Start Block
We want trigger this automation every time someone publish an app. In the Start Block select:
Anytime an app will be published to a space, Qlik Cloud Service connector will pass all the informations about the published app in the JSON format above. Those informations can be used by downstream blocks. It is not convenient continuosly publish apps to test the process, especially during the build phase. For this reason the Payload Test is used when we hit the RUN button, therefore just replace:
<YOUR ATTRIBUTE ID> with the app id we want to emulate for a publish action
<YOUR ORIGINAL APP ID> for the purpose of this guide you can set this as app is as well.
<YOUR SPACE ID> with the target space id we want emulate for the publish action
because the downstream blocks are going to use only those three pieces of information, we don't need to change other attributes.
Get Space Info
From the Qlik Cloud Service Connector drag and drop in the canvas the Get Space block and attach it to the Start block. Under the Input select App Published > Data > Space Id as Space Id
Get Space Block
This block is in charge of getting all the informations giving the published space id.
Make it Parametric
Static contents such as the Repository Owner and Name can be used in more blocks. It may be convenient to set variables with static content and use variables in the downstream blocks. Variables make this automation easier to mantain.
On the left hand-side menu click on Basic under BLOCKS and in the submenu select Variable block. Drag it into the canvas under the Get Spaceblock
Variable Block properties
On the variable Input section click on the Manage Variables button, the variable dialog window will open. Add two new variables (owner and repo, optianally branch) and select type string for both, then click Save.
Variables dialog window
You need to use one variable block to set each variable, thuse you need to use two variable blocks chained one after the other to set the Github Owner and Repo.
We want only production spaces app are backed up and versioned on the github repository and this is the right moment to check it.
On the left hand-side menu click on Basic under BLOCKS, in the submenu select Condition block, move it into the canvas under your last variable block.
Condition Block properties
In the IF statement, click on the little down arrow icon and select the Get Space block, then Description. Next select Contain and in the last box just write Production. This statement will return true when the target space description will contain the word Production.
Get App Information
We need some information about the published app to use later downstream in the process. From the Qlik Cloud Service Connector, select the Get App Information block and drop it in the YES branch under the Condition block. In the App Id box select App Published > Data > Attributes > id.
Get App Information properties
Next step is to export the published app. From the Qlik Cloud Service Connector, select the Export App to Base 64 Encoded File block and drop it under the previous block. In the App Id select:
App Published > Data > Attributes > Original App Id
Export App to Base 64 Encoded File
Move to Github
Now we are ready to move the file into GitHub repo created earlier. In case of file update, we need to get the SHA signature of the file being replaced, for this reason we need to use the Get Repository Content block. This block return several informations giving the file name, we are only interested in the SHA signature.
From the GitHub Connector, select the Get Repository Content block and drop it under the previous block. In the input section fill the fields as follow.
User: Variable Owner
Repo: Variable Repo
Path: Get Space > Name / Get App information > Info > Attributes > Name .qvf
Get Repository Content
As you can see from the above image, the path was built using the space name as folder name and the app name as file name. We also added the slash (/) between the folder and file name, and the file extension (.qvf).
The first time we push a new App, the related file does not exist yet on the Github repo, thuse this block will return an error, but we don't want to block the whole process. For this reason we want to just raise a warning.
In the Settings section select Warnings as On Error action, as showed in the following image.
On Error action
We are ready now to push the file up to the GitHub repository. From the GitHub Connector, select the Create or Update File Contents block and drop it under the previous block. Under the Input section fill the properties as follow:
Owner : Get it from the variable
Repository: Get it from the variable
Message : Get App Information > Info > Attributes > Description
Path: Get Space > Name / Get App information > Info > Attributes > Name .qvf
Base 64 File Content: Get it from the previous block
Branch: Main (or use a variable)
File Sha: Get Repository Content > Sha
IMPORTANT : If you map the Message field, then you must set a message on the the publish action or the automation will fail. You can optionally avoid mapping the message field. Thanks to @Alvaro_Palacios for the find
Create or Update File Contents
So far so good, we have the app saved into GitHub repo, the next three bloks are used to alert the App owner and users interested in a new published version. Let's start getting the user e-mail.
From the Qlik Cloud Service Connector, select the Get User block and similarly as already done so far, in the User Id fields select
App Published > Extensions > User Id
Next attach the Send Mail block and fill the fields as reported in the following image. This block will send some useful information to the app owner.
Send Mail PropertiesThe last step is send a message on a pre-defined Microsoft Teams Channel alerting a new version of the app has been published and available.
From Microsoft Teams Select Send Message block and fill the fields as showed in the following image
Send Message Properties
And this is how the alert message in the Team channel looks like.
Message in teams
Going through all these steps is the best way to getting start with the Qlik Application Automation logic, but if you are in a hurry and just need this process to work, all you need to do is download the attached JSON, right click on an empty space in the canvas and select upload workspace.
Once uploaded, remember to authenticate all the involved connectors and change the variables value.
September 23: Thanks to some of you who have tested this automation, it turns out the Get Repository Content Block have an hard limit on the file size, leading the automation to fails updating file greather then 1Mb. That block can easly replaced by the Get Repository Content and filter the file we are interested in.
Here attached the Fixed version.
The information in this article is provided as-is and to be used at own discretion. Depending on tool(s) used, customization(s), and/or other factors ongoing support on the solution below may not be provided by Qlik Support.