You are here

Creating a Testcomplete build step in Jenkins with Job DSL which executes all function i a Testcomplete unit file

I have been working with Jenkins CI for some weeks, and we have grown out own the Jenkins Plugin for handling TestComplete tests as a test step. So I have created a dynamic creation of a job in Jenkins.
My need was to execute all the test (functions or methods), present in a given unit which is part of my TestComplete Project. The basis of this need, is another story about dynamically generated tests. which is written to that unit.
The DSL for the job is pretty strait forward.

To be able to run this Jenkins job generation, you need to have the Job DSL plugin installed in your Jenkins.
and the: TestComplete Support Plugin
Lastly viewing the result is nice using this plugin: TestComplete xUnit Plugin
The JobDSL uses Groovy as scripting Langue. Groovy is a Java like language. But it is dynamic, and have all which is available in Java, available too. Which is nice.

import java.util.regex.*

// defining the job and job name
def myJob = freeStyleJob('DynamicTestCompleteJenkins')

myJob.with {
    // Setting a description text in the description field
    description 'Dynamic TestComplete Jenkins Job'
        //  Setting the TestComplete unit file extension
	def unitExt = '.sj'
        // The complete test suite path
	def suitePath = '[SUITE PATH]'  
        // Set the Test Suite name
	def suiteName = '[SUITE NAME]' // Without file extension 
        // Set the Project name
	def projectName = '[PROJECT NAME]' // Without file extension
        // Set the Unit name
	def unitName = '[UNIT NAME]' // Without file extension

        // Finalising the suiteName for use in the job description
	suiteName = suitePath + suiteName + '.pjs'  
        // Finalising the filename for use in the job description
	def filename = suitePath + projectName + '\\Script\\' + unitName + unitExt

        // Reading the unit file	  
	def data = readFileFromWorkspace(filename)
	String[] unitLines = data.split("\n")
	def routineName=''
	        // looking for "function"
		for (def unitLine : unitLines) {   
		  if (unitLine.contains('function')) {
			unitLine = unitLine.replace('function','')
			unitLine = unitLine.replaceAll("[^A-Za-z0-9()\\[\\]]", "");
			unitLine = unitLine.replace('()','')
			unitLine = unitLine.replace('{','')
			unitLine = unitLine.trim()
			out.println('Unit for execution: '  + unitLine)
                        // The name of the routing or function is found
			routineName = unitLine
                          // Configuring the job xml
			  configure {
				it / builders 

More info here: