Worksoft Certify’ s Execution Manager is the perfect solution to execute your Certify tests lights-out. It can schedule and manage remote execution of your Certify processes. You can run tests on a pre-determined schedule or on demand. Execution Manager can also manage your testing resources and resource users centrally for execution.Execution Manager is a must have product for your light-out regression testing which is otherwise cumbersome. To know more about Certify Execution Manager, visit http://docs.worksoft.com.
Jenkins is an open source tool built using Java for continuous integration/testing. Jenkins is used to build and test your projects continuously making it easier for developers to integrate changes to the project. To know more about Jenkins, visit https://jenkins.io/.
This blog will be helpful if you already have Certify Execution Manager and Jenkins in your organization and looking forward to using it for continuous testing. Jenkins can help you orchestrate your Certify EM Request execution based on your execution flow requirements.
You can also use Worksoft Execution Manager Jenkins plugin to trigger EM requests from Jenkins. To know more about this plugin, visit https://wiki.jenkins.io/display/JENKINS/Worksoft+Execution+Manager+Plugin.
In this blog, I am going to show you how to trigger an EM request from Jenkins without using the plugin mentioned above.
Pre-Requisites
- Jenkins: Jenkins needs to be installed on a server/machine that can access your Worksoft Execution Manager. Make sure you have installed the “PowerShell” plugin in Jenkins https://plugins.jenkins.io/powershell.
- Worksoft Execution Manager:Require 10.0 or above as these have restful API’s enabled for other applications like Jenkins to orchestrate EM execution. For more info on the API’s please check the below URL in your browser based on your Worksoft EM installation server and you should see the below screen.
URL : http://
(Your EM URL followed by /apidocs/index.html at the end)
Steps:
- Create an EM Request: The first step is to have an EM request created. If you are new to Execution Manager, please check the link to learn how to create one.
Once your request is created, make you press the “Play” button to allow the request to execute Certify processes.
Note down the Request ID of the request you created in EM. This will be used by Jenkins to trigger the request.
If you are not able to view the Request ID column, right-click on the column and add the “Request ID” as shown below.
2.Login to Jenkins and Create a Build:
The URL of your Jenkins installation should look something like below.
http://localhost:8080/ Local Installation
http://
Login to the Jenkins with your credentials as shown below.
In the dashboard screen, click on the “New Item” link as shown below to create a new build.
Enter a name for your build/project and choose “Freestyle Project” as the project type and click OK.
3. Add PowerShell script:
In the Build section, click on the “Windows PowerShell” option.
Note: This option will be visible only if you have installed the PowerShell plugin mentioned above in the pre-requisites section.
Paste the below code in the text area as shown below.
# Obtain the bearer token, trim it to get access_token into a variable.
$tokenrequest = @{ “grant_type” = “password”; “username” = “$ENV:EMUsername”; “password” = “$ENV:EMPassword” }
$token = Invoke-RestMethod -Uri “$ENV:EndPoint/Token” -ContentType application/x-www-form-urlencoded -Headers @{ Authorization = (“OAuth2″)} -Method POST -Body $tokenrequest
$token = $token.access_token
Write-Output $token
# Assign the Request ID parameter:
$RequestID = $ENV:RequestID
# Declare URL and Headers and make a post call to trigger a request in Execution Manager:
# fully qualified URL to Execution Manager execute request
$URL=”$ENV:EndPoint/ExecuteRequest/”
# setup headers to make call to run request
$execheader = @{id=$RequestID; Authorization=’Bearer ‘+$token}
# $execheaders.Add(“parameters”, $BuildNumberStr)
# call Execution Manager and get response GUID
Write-Output “Trigger EM request started”
$Response = Invoke-RestMethod -Method Put -Uri $URL -Headers $execheader
Write-Output “response has started GUID is ”
Write-Output $Response
# Fetch the status and loop thru until the status is returned ‘Completed’:
# setup fully qualified URL to Execution Manager status
$URL2=”$ENV:EndPoint/ExecutionStatus/”
$execstatusheader = @{APIRequestID = $Response; Authorization=’Bearer ‘+$token}
Write-Output “Checking status every 15 seconds”
# create loop and look at status for 5 minutes checking every 5 seconds
$timeout = new-timespan -Minutes 25
$sw = [diagnostics.stopwatch]::StartNew()
while ($sw.elapsed -lt $timeout){
$Response2 = Invoke-RestMethod -Method Get -Uri $URL2 -Headers $execstatusheader
if ($response2.Status -eq “Completed”){
write-Output “Certify Process completed”
break
}
start-sleep -s 15
Write-Output “Still waiting …”
}
Write-Output “Checking status completed”
# Fetch the status of request after the execution is finished:
# Fetch the status of the request after the request is completed executing and set the error codes based on the status.
# make the call 1 more time to update the variables
$response2 = Invoke-RestMethod -Method Get -Uri $URL2 -Headers $execstatusheader
Write-Output “Running Tests Status”
Write-Output $response2
Write-Output ” ”
# Write-output $response2.Status
# Write-Output $response2.Description
if ($response2.Description -eq “Passed”){
write-Output “Certify Process completed successfully”
exit 0
}
write-Output “Certify Process Failed”
exit 1
4. Create Environment variables:
For the above script to run, you will need to add the below 4 parameters to your build.
EMUsername (String Parameter)
EMPassword (Password Parameter)
EndPoint (String Parameter)
RequestID (String Parameter)
Follow the below steps to create these parameters in the “General” section.
Once you have added the above parameters, Click on Save.
5. Execute the build in Jenkins:
Click on Build to start the execution.
Your build history should show the current execution. Click on the highlighted region to view the console.
You should see the console output of the current execution
You should also see your EM request running
Once the execution is done, you should see the below console output in Jenkins
Note: The Description will show as “Failed” if the execution fails.
Reference and Credit