Integrate with Jenkins

abstract Jenkins and other Continuous Integration systems can trigger Sahi Pro Flowcharts as part of the build process using Sahi's ANT target.

Sahi Pro Flowcharts with Jenkins

Automation is useless without Continuous Integration. Sahi Pro Flowcharts should be periodically executed and CI systems can trigger execution when code changes happen. Sahi Pro Flowcharts can be triggered via ANT. We configure Jenkins to call Sahi's ANT target and then make Sahi's report accessible from Jenkins.

Sahi Pro needs real browsers to playback test scenarios. But most Jenkins/build machines run in server mode and do not have a GUI. This forces end users to either try with headless browsers or to execute Sahi scripts remotely.

With Sahi, this is what you can do:

Jenkins machine (J): Run Jenkins on server. No Sahi installed.
Sahi Master machine (SM): Sahi Pro Runner (or Sahi Pro) runs on this machine and behaves as Master
Sahi slave machines (SL1, SL2, SL3): These are slave machines with Sahi Pro Runner (or Sahi Pro) running on them.
Central Database: Sync all the logs from Sahi Master to this machine. For more info, look at Sahi Sync DB.

During the build process:

Jenkins pulls the latest scripts from the Source Control Management (SCM) system. It calls the Sahi ant target. Sahi target copies over the scripts from Jenkins (J) to master (SM). SM then copies scripts to SL1, SL2, SL3, distributes the execution and collects all reports. Sahi ant target then pulls reports from SM to Jenkins. This allows Jenkins to remain a headless server and does not need Sahi installed on it. Also, all distribution of scripts and pulling of reports happens through Sahi's ant target itself.

infoWe recommend using Sahi Pro Runner on master, slave and central reports database machines

Prerequisites

Before integration, you will first need an ant target to run the flowchart file. You can create the ANT target using Run Settings dialog. Save the file in any path accessible by Jenkins (say C:\jenkins_sahi) and let's call it build.xml.

info At the end of the configuration steps in this page, your folder structure should look like this:
C:
  |--jenkins_sahi
         |
         |--build.xml
         |--email.properties
         |--lib
             |
             |--ant-sahi.jar
In the build.xml make sure that: Also Install the HTML Publisher plugin if you wish to see HTML logs via Jenkins UI.

Let us assume that Jenkins is available in C:\.jenkins\

Configure Jenkins

View Sahi Pro Flowcharts Reports in Jenkins

info Note: You need to have HTML Publisher plugin installed. Make sure you have configured HTML Reports as described in the section above. Also, If you are using Jenkins 1.625.3 or above, and if you are not able to view HTML Reports correctly, follow the below steps.
warningRead the Content Security Policy here As these versions of Jenkins has introduced Content-Security-Policy to protect Jenkins users from malicious HTML/JS files in workspaces, /userContent, or archived artifacts.
  • If starting Jenkins using jenkins.war file then use the below command.
    java -Dhudson.model.DirectoryBrowserSupport.CSP= -jar jenkins.war
  • If starting Jenkins as a service on a Windows machine:
    • Go to <Home>/.jenkins/jenkins.xml file, and add "-Dhudson.model.DirectoryBrowserSupport.CSP=\"\"" under the <arguments> Tag. After adding the property in the <arguments> tag, the tag will look as below.
      <arguments>-Xrs -Xmx256m -Dhudson.lifecycle=hudson.lifecycle.WindowsServiceLifecycle "-Dhudson.model.DirectoryBrowserSupport.CSP=\"\"" -jar "%BASE%\jenkins.war" --httpPort=8080 --webroot="%BASE%\war"</arguments>
    • Save the file, Restart Jenkins.
  • If starting Jenkins as a service on a Linux machine:
    • Create a new directory with name init.groovy.d in Jenkins home directory /var/jenkins_home.
    • Within init.groovy.d directory create a new groovy script. Say startup-properties.groovy
    • Copy the below content to the startup-properties.groovy file.
      import jenkins.model.Jenkins
      import java.util.logging.LogManager
      /* Jenkins home directory */
      def jenkinsHome = Jenkins.instance.getRootDir().absolutePath
      def logger = LogManager.getLogManager().getLogger("")
      /* Replace the Key and value with the values you want to set.*/
      /* System.setProperty(key, value) */
      System.setProperty("hudson.model.DirectoryBrowserSupport.CSP", "")
      logger.info("Jenkins Startup Script: Successfully updated the system properties value for hudson.model.DirectoryBrowserSupport.CSP . Script location : ${jenkinsHome}/init.groovy.d ")
    • Save the file, Restart the Jenkins server.
Once HTML Reports are configured, one can view Sahi's report logs by clicking on the "HTML Reports" link on the left side navigation links on the Jenkins project page. Sahi Pro Flowcharts Report looks like this: