how to get the testcomplete actiononerror status in jenkins pipeline
SOLVED- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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
Solved! Go to Solution.
- Labels:
-
Command Line
-
Test Results
-
Web Testing
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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.
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Waiting for your respond
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I tried the solution as @KB1 mentioned, but I am not getting the email on error. Below is the log from the jenkins console
This is the log when I don't use the error method
Am I missing anything here?
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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.
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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')
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
@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)
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
