Ask a Question

how to get the testcomplete actiononerror status in jenkins pipeline

SOLVED
tvklovesu
Frequent Contributor

how to get the testcomplete actiononerror status in jenkins pipeline

Hello,

I have tests running in jenkins pipeline and I have the following script to run the test and send the email at the end of the test. But I want to make the email sent with condition where if the actionOnError = Make_Failed then send the email

 

node("windows") {
     git credentialsId: 'GitHub-clientid', url: 'https://github.xxx.com/ea-e2e-test.git', branch: 'master'
     withVault(configuration: [timeout: 60, vaultCredentialId: 'credensid', vaultUrl: 'https://vault.xxx.com'],
     vaultSecrets: [[engineVersion: 1, path: 'secret/cloudbees/platforms/testing',
     secretValues: [[envVar: 'USERNAME', vaultKey: 'username'], [envVar: 'PASSWORD', vaultKey: 'password']]]]) {
            testcompletetest commandLineArguments: "/run /psv:env=pro /psv:username=${USERNAME} /psv:password=${PASSWORD}", generateMHT: true, launchType: 'lcProject', actionOnErrors: 'MAKE_FAILED', project: 'TestProject_EAProd', suite: 'TestProject_EA.pjs'
    }

// here I need to check that actionOnErrors value and if its only when failed then send the email. 

  if (actionOnErrors=='MAKE_FAILED'){

    emailext (
      subject: 'EA Smoke test results in Prod',
      body: 'Please click below to access the test results \n' + env.BUILD_URL+'/TestComplete/',
      to: 'abc@gmail.com',
      from: 'donotreply@cloudbees.xxx.com')
   }

}

 

TIA

11 REPLIES 11
KB1
Frequent Contributor

To achieve what you want, you can use the error step in your pipeline to check if the previous stage has failed. If it has failed, the error step will execute and you can send the email notification inside it.

Here's an example of how you can modify your pipeline script:

 

 

node("windows") {
     git credentialsId: 'GitHub-clientid', url: 'https://github.xxx.com/ea-e2e-test.git', branch: 'master'
     withVault(configuration: [timeout: 60, vaultCredentialId: 'credensid', vaultUrl: 'https://vault.xxx.com'],
     vaultSecrets: [[engineVersion: 1, path: 'secret/cloudbees/platforms/testing',
     secretValues: [[envVar: 'USERNAME', vaultKey: 'username'], [envVar: 'PASSWORD', vaultKey: 'password']]]]) {
            testcompletetest commandLineArguments: "/run /psv:env=pro /psv:username=${USERNAME} /psv:password=${PASSWORD}", generateMHT: true, launchType: 'lcProject', actionOnErrors: 'MAKE_FAILED', project: 'TestProject_EAProd', suite: 'TestProject_EA.pjs'
    }
    // Use the error step to check if the previous stage has failed
    error {
        // If the previous stage has failed, send the email notification
        emailext (
          subject: 'EA Smoke test results in Prod',
          body: 'Please click below to access the test results \n' + env.BUILD_URL+'/TestComplete/',
          to: 'abc@gmail.com',
          from: 'donotreply@cloudbees.xxx.com')
    }
}

 

 

This way, the email notification will only be sent if the previous stage (i.e., the testcompletetest step) has failed. If the previous stage has succeeded, the error step will be skipped and the email notification will not be sent.

I hope this helps! Let me know if you have any questions.

tvklovesu
Frequent Contributor

Thanks @KB1, I will try this and will let you know the outcome.

KB1
Frequent Contributor

Waiting for your respond

tvklovesu
Frequent Contributor

I tried the solution as @KB1 mentioned, but I am not getting the email on error. Below is the log from the jenkins console

 

tvklovesu_0-1671809487598.png

This is the log when I don't use the error method

tvklovesu_1-1671809590173.png

Am I missing anything here?

KB1
Frequent Contributor

 

It looks like you are getting a ClassCastException error when running your Jenkins pipeline. This error is caused by an issue with the error step you have added to your script.

The error step expects a string argument that specifies the error message to be displayed. However, in your script, you are passing a closure (i.e., the code block inside the error step) as the error message. This is causing the ClassCastException error.

To fix this issue, you need to remove the code block inside the error step and pass a string argument as the error message instead. Here's an example of how you can do this:

 

 
node("windows") {
  git credentialsId: 'GitHub-clientid', url: 'https://github.xxx.com/ea-e2e-test.git', branch: 'master'
  withVault(configuration: [timeout: 60, vaultCredentialId: 'credensid', vaultUrl: 'https://vault.xxx.com'],
  vaultSecrets: [[engineVersion: 1, path: 'secret/cloudbees/platforms/testing',
  secretValues: [[envVar: 'USERNAME', vaultKey: 'username'], [envVar: 'PASSWORD', vaultKey: 'password']]]]) {
          testcompletetest commandLineArguments: "/run /psv:env=pro /psv:username=${USERNAME} /psv:password=${PASSWORD}", generateMHT: true, launchType: 'lcProject', actionOnErrors: 'MAKE_FAILED', project: 'TestProject_EAProd', suite: 'TestProject_EA.pjs'
  }
  // Use the error step to check if the previous stage has failed
  error 'Test failed. Sending email notification.'
  emailext (
    subject: 'EA Smoke test results in Prod',
    body: 'Please click below to access the test results \n' + env.BUILD_URL+'/TestComplete/',
    to: 'abc@gmail.com',
    from: 'donotreply@cloudbees.xxx.com')
}

This script will still check whether the previous stage has failed and send the email notification if it has. However, it will not throw the ClassCastException error anymore.

I hope this helps! Let me know if you have any questions.

tvklovesu
Frequent Contributor

Thanks for the help. Actually when I tried your solution it did removed the ClassCastException error, but I still didn't get the email on error. After I add ',' next to that error message then it sent the email on error too.

 

error 'Test failed. Sending email notification.',
  emailext (
    subject: 'EA Smoke test results in Prod',
    body: 'Please click below to access the test results \n' + env.BUILD_URL+'/TestComplete/',
    to: 'abc@gmail.com',
    from: 'donotreply@cloudbees.xxx.com')
KB1
Frequent Contributor

I’m at this moment on my way home, when I reach home I’ll look again
tvklovesu
Frequent Contributor

@KB1 , So even when I don't have any test failures I still got the email and the following error in the console. Do we need to provide any other text if there is no error?

 

java.lang.IllegalArgumentException: Expected named arguments but got [Test failed. Sending email notification., null]
	at org.jenkinsci.plugins.workflow.cps.DSL.parseArgs(DSL.java:708)
	at org.jenkinsci.plugins.workflow.cps.DSL.parseArgs(DSL.java:635)
	at org.jenkinsci.plugins.workflow.cps.DSL.invokeStep(DSL.java:234)
	at org.jenkinsci.plugins.workflow.cps.DSL.invokeMethod(DSL.java:193)
	at org.jenkinsci.plugins.workflow.cps.CpsScript.invokeMethod(CpsScript.java:122)
	at sun.reflect.GeneratedMethodAccessor2085.invoke(Unknown Source)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.lang.reflect.Method.invoke(Method.java:498)
	at org.codehaus.groovy.reflection.CachedMethod.invoke(CachedMethod.java:93)
	at groovy.lang.MetaMethod.doMethodInvoke(MetaMethod.java:325)
	at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:1213)
	at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:1022)
	at org.codehaus.groovy.runtime.callsite.PogoMetaClassSite.call(PogoMetaClassSite.java:42)
	at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:48)
	at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:113)
	at org.kohsuke.groovy.sandbox.impl.Checker$1.call(Checker.java:163)
	at org.kohsuke.groovy.sandbox.GroovyInterceptor.onMethodCall(GroovyInterceptor.java:23)
	at org.jenkinsci.plugins.scriptsecurity.sandbox.groovy.SandboxInterceptor.onMethodCall(SandboxInterceptor.java:157)
	at org.kohsuke.groovy.sandbox.impl.Checker$1.call(Checker.java:161)
	at org.kohsuke.groovy.sandbox.impl.Checker.checkedCall(Checker.java:165)
	at org.kohsuke.groovy.sandbox.impl.Checker.checkedCall(Checker.java:135)
	at com.cloudbees.groovy.cps.sandbox.SandboxInvoker.methodCall(SandboxInvoker.java:17)
	at WorkflowScript.run(WorkflowScript:13)

 

 

tvklovesu
Frequent Contributor

@KB1, Still waiting for your reply about the issue I am having.

cancel
Showing results for 
Search instead for 
Did you mean: