Using Jenkins Plugin for CA Service Virtualization

The CA Service Virtualization plugin for Jenkins lets you manage virtual services and provision tests on CA Service Virtualization Enterprise Edition from your Jenkins UI.
dts103
The CA Service Virtualization plugin for Jenkins lets you manage virtual services and provision tests on CA Service Virtualization Enterprise Edition from your Jenkins UI.
Visit the DevTest Community pages to provide feedback and receive community support.
This section contains the following information:
2
Prerequisites
The plugin has the following prerequisites:
  • DevTest 10.3 installation or later.
  • Jenkins 2.73.3 or later.
Install
The following link will take you to the Jenkins page for CA Service Virtualization: 
The page above includes a link to GitHub. You can download the source code from GitHub if you wish to fork the project and make changes to the code. Otherwise use the Plugin Manager to install the plugin from Jenkins.
Install this plugin with the Jenkins Plugin Manager. 
For details on how to use the Jenkins Plugin Manager, see the Jenkins documentation page: Managing Plugins.
Configure
Follow these steps:
  1. In the Jenkins Plugin window, select 
    Manage Jenkins
     and then select 
    Configure System.
  2. Complete the following fields under 
    CA Service Virtualization Configuration
    :
    • Registry Host URL (Registry IP address/hostname).
    • Port (Port of Registry endpoint).
    • Registry Credentials. Use the Jenkins credentials plugin (username/password credentials).
    • Select the
      Use https
      checkbox if your DevTest API is set up to use https security.
The host and port information can be found in the LISA properties file. The username and password are stored in the database.
      3. Click 
Test Connection.
 
      4. Click 
Save.
configure_3.png
: Individual projects can override the global connection settings using the custom registry endpoint option.
Features
The Features of the Jenkins Plugin for CA Service Virtualization can be configured in the
Build
settings of the plugin.  
Add a new build step
  1. Select  
    Add build step
    under the
    Build
    section.
  2. Choose the step you want to add from the drop-down list. 
  3. Define the parameters.
     
Configure existing build steps
  1. Choose the existing item that you want to configure from the home screen of the Jenkins plugin.
  2. Select the individual step and select
    Configure 
  3. Define the parameters under the
     
    Build
    section.
Use a custom registry endpoint
You can use a custom registry endpoint for each build step to override the default parameters. To use a custom registry, select the
Use custom registry endpoint
 checkbox under the build step and complete the required fields.
CustomReg2.png
Features Include: 
: All features support Jenkinks parameters. Select
This Project is parameterized
option in the project configuration to enable the jenkins parameters.
Deploy Virtual Services
To deploy a Virtual Service with a MAR file, enter the
VSE name
and the
MAR file
location. 
Deploy new_2PNG.PNG
Example paths to the MAR file:
  • dir/test.mar 
    Relative path to MAR file in job workspace.
  • **/*.mar
    Wildcard format to match all MAR files within the recursive directory structure.
  • artifacts/*.mar
    Wildcard format to match all MAR files within a specific directory.
  • file:///C:/something/test.mar 
    Points to the MAR file on file system of the DevTest machine.
  • http://something/test.mar
    HTTP location of the MAR file.
The MAR File field supports multiple strings delimited by either a separate line or a comma.
Deploy Test Cases and Test Suites
To deploy and start test cases and test suites, select the
Test Type
from the drop-down list and enter the MAR file path in the
MAR file
field. 
The chosen Test Type must match the contents of the MAR file. For example, if the Test Type is set to 
Test 
the MAR file must contain test. If the Test Type is set to
testsuite
the MAR file must contain testsuite.
deploy_test_cases .png
Here is how Test Case results in CA Service Virtualization map to Build Step results in Jenkins:
Test Case Result
Jenkins Build Step Result
Failed
UNSTABLE
FAILED_TO_STAGE | ABORTED
FAILURE
Others
PASSED
A failed test case maps to UNSTABLE instead of FAILURE because a single test case failure should not necessarily fail the whole build, especially when you could have multiple test cases running in different build steps.
: The MAR file must be located in the workspace of the job.
: To generate a report, select 
CA Service Virtualization Report Publisher
from the drop down under 
Post-Build Actions.
Start, Stop, or Undeploy Virtual Services
To start, stop or undeploy Virtual Services, define the
VSE name
and the
VS names
for the chosen function.
Start Virtual Service.PNG
The
VS names
field supports multiple strings delimited by a separate line.
Pipeline Support
Pipeline scripts are also supported to configure the plugin and execute commands.
For more information about the Jenkins Pipeline available commands provided by the plugin see: CA Service Virtualization plugin Pipeline reference documentation.
See the following examples for each build step:
Deploy Virtual Service
Example 1: 
Deploy the virtual service by specifying a custom Registry endpoint (This also overides the global configuration for the Registry endpoint).
node {
    stage('SCM') {
        git credentialsId: 'gitCred', url: 'https://github.com/foo/bar.git'
    }
    stage('CA Service Virtualization Deploy VS') {
        // Overriding global configuration for DevTest Registry endpoint
        svDeployVirtualService marFilesPaths: 'jenkins-plugin/webservices-vs.mar', vseName: 'VSE' , useCustomRegistry: true, host: 'DevTestHost.com', port: '1505', secured: true, tokenCredentialId: 'DevTestCred'
    }
}
Example 2: Deploy the virtual service with the global configuration for the Registry endpoint.
node {
    stage('SCM') {
        git credentialsId: 'gitCred', url: 'https://github.com/foo/bar.git'
    }
    stage('CA Service Virtualization Deploy VS') {
        svDeployVirtualService vseName: 'VSE', marFilesPaths: 'http://share.com/vs.mar\nfile:///C:/VS/webservices.mar'
    }
}
Deploy and Run Test 
node {
    stage('SCM') {
        git credentialsId: 'gitCred', url: 'https://github.com/foo/bar.git'
    }
    stage('CA Service Virtualization Start Start') {
        svDeployTest testType: 'tests', marFilePath: 'folder/test.mar'
    }
   
//Include the following lines if you want to generate test reports:
    stage('Generate test reports') {
        svPublishTestReport()
    }
}
Deploy and Run Test Suite
node {
    stage('SCM') {
        git credentialsId: 'gitCred', url: 'https://github.com/foo/bar.git'
    }
    stage('CA Service Virtualization Start TestSuite') {
        svDeployTest testType: 'suites', marFilePath: 'folder/testsuite.mar'
    }
   
//Include the following lines if you want to generate test reports:
    stage('Generate test reports') {
        svPublishTestReport()
    }
}
Stop Virtual Services
node {
    stage('CA Service Virtualization Stop VS') {
        svStopVirtualService  vseName: 'VSE', vsNames: '''WebServicesModel'''
    }
}
Start Virtual Services
node {
    stage('CA Service Virtualization Start VS') {
        svStartVirtualService vseName: 'VSE', vsNames: '''WebServicesModel\nwebservices-vs'''
    }
}
Undeploy Virtual Services
node {
    stage('CA Service Virtualization Undeploy VS') {
        svUndeployVirtualService vseName: 'VSE', vsNames: '''WebServicesModel\nwebservices-vs'''
    }
}