Forum Discussion

tvklovesu's avatar
tvklovesu
Frequent Contributor
2 years ago
Solved

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

  •  

    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.

11 Replies

  • KB1's avatar
    KB1
    Champion Level 2

    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's avatar
      tvklovesu
      Frequent Contributor

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

      • KB1's avatar
        KB1
        Champion Level 2

        Waiting for your respond

  • KB1's avatar
    KB1
    Champion Level 2

     

    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's avatar
      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's avatar
        KB1
        Champion Level 2
        I’m at this moment on my way home, when I reach home I’ll look again