Forum Discussion
I think I don't have permission to do that as I am not admin. Is there any other way to achieve this without requesting my admin to approve this? Because I need to reuse the same method in multiple pipelines.
Try to disable "Use Groovy Sandbox" option in your pipeline if it is enabled. If this does not work, you need to be an admin or ask your Jenkins admin to add signatures or disable script security completely.
- Bonibom3 years agoContributor
You can modify variables in the condition block (where you check exit code contains -1) and use those variables in the body, subject in the emailext or everywhere you need in the pipeline. If you meant that. But this does not relate to topic the current thread and more relate to general programming.
- tvklovesu3 years agoFrequent Contributor
If I uncheck that box then I am getting a message for approving the script
So don't we have any other way to read the console output?
- Bonibom3 years agoContributor
You can try
1. currentBuild.rawBuild.log (this might be deprecated but let's try)
2. global variable manager using manager.logContains(text) (never tried that )
Anyway, the best way is using Jenkins API methods in your scripts as you may need various methods in the future.
- tvklovesu3 years agoFrequent Contributor
For manager I got the following
[GitHub Checks] GitHub check (name: Jenkins, status: COMPLETED) has been published. hudson.remoting.ProxyException: groovy.lang.MissingPropertyException: No such property: manager for class: WorkflowScript at org.codehaus.groovy.runtime.ScriptBytecodeAdapter.unwrap(ScriptBytecodeAdapter.java:53) at org.codehaus.groovy.runtime.ScriptBytecodeAdapter.getProperty(ScriptBytecodeAdapter.java:458)
- tvklovesu3 years agoFrequent Contributor
Thanks for your help. Finally, I am able to read the exit code and send the emails only when the exit code is -1. Here is my script for anyone else need it later.
stage('Checking log'){
steps{
script{
//List<String> log= currentBuild.rawBuild.getLog(100)
boolean Pass= currentBuild.rawBuild.getLog(100).contains("[TestComplete] Test runner exit code: 0.")
boolean Fail= currentBuild.rawBuild.getLog(100).contains("[TestComplete] Test runner exit code: 2.")
boolean error= currentBuild.rawBuild.getLog(100).contains("[TestComplete] Test runner exit code: 3.")
boolean license= currentBuild.rawBuild.getLog(100).contains("[TestComplete] Test runner exit code: -1.")
if (Pass)
{
echo 'Passed'
}else if (Fail){
echo "Failed."
emailext (
subject: "Core application Failed to login in Prod",
body: "Core application seems to be failed to login in Prod. Please click the link to access the test results for more details \n" + env.BUILD_URL+"TestComplete/",
to: 'xyz@xxx.com, abc@xxx.com, 123@xxx.com'
from: "donotreply@cloudbees.com")
}
else if (error || license){
echo "Error or License"
emailext (
subject: "TestComplete has error to run in jenkins",
body: "TestComplete failed to run in Jenkins. Please click the link to access the test results for more details \n" + env.BUILD_URL+"TestComplete/",
to: 'xyz@xxx.com'
from: "donotreply@cloudbees.com")
}
}
}
}