Error while trying to capture Jenkins error message - getRawBuild method restriction

Hi,

I am trying to capture the last error line from Jenkins console output that starts with the word ERROR. My goal is to identify the exact error message in the pipeline console log. However, I ran into an issue when attempting to implement the following code:

[Pipeline] // withCredentials
[Pipeline] }
[Pipeline] // withEnv
[Pipeline] }
[Pipeline] // node
[Pipeline] End of Pipeline
ERROR: Error during the Checkout and Build Modules stage: Unable to create live FilePath for docker-slave; docker-slave was marked offline: Node is being removed
Finished: FAILURE

I tried to use the getRawBuild() method to extract the error, but I received the following error message:

Scripts not permitted to use method org.jenkinsci.plugins.workflow.support.steps.build.RunWrapper getRawBuild. Administrators can decide whether to approve or reject this signature.

Could someone guide me on how to properly capture the error line in the Jenkins console output without running into script approval issues? Is there a more Jenkins-safe way to extract this information?