Your browser was unable to load all of the resources. They may have been blocked by your firewall, proxy or browser configuration.
Press Ctrl+F5 or Ctrl+Shift+R to have your browser try again.

Saving step error message #3798

stephasaurus ·

Hi - so in our post-build command, we have a script that analyzes error messages and adds some messaging so the user can better understand what happened during the build. We are using step.setErrorMessage(string) to append to the original error message, but I don't think it is saving. Is there anything we need to do to make sure the text we set in step.setErrorMessage() actually saves back to the step/build? I haven't seen a "save()" function anywhere for either build or step.

Thanks!

  • replies 7
  • views 480
  • stars 0
robinshen ADMIN ·

Post build command will not affect build status and step messages. You may consider to call your command in a step instead of post-build script.

stephasaurus ·

So is there a way to alter a step's error message after the build has run without it being a step inside the build itself?

Like if I load the build, iterate through the steps, change the error message and then save the build back to the DB, will that work?

robinshen ADMIN ·

Yes you can do that by direct modifying the build object, something like below:

groovy:
def buildToBeModified = system.buildManager.load(buildId);
def step = buildToBeModified.getStep("master>path>to>some>step");
step.setErrorMessage("anther error message");
step.setStatus(com.pmease.quickbuild.stepsupport.Step.Status.FAILED);
system.buildManager.save(buildToBeModified);
stephasaurus ·

So will that work if I do it inside a post-build command? So if I did it inside buildToBeModified's post-build script (in Advanced Setting) it would work? Or at that point has the build not really saved back to the DB and whatever I do will be overwritten?

Thanks!

robinshen ADMIN ·

Yes you can do that in post-build script as build has already been saved at that point. Your changes will not be overwritten.

OnQuickBuild ·

Hi Robin

I have an "execute script" step. And I use groovy and assertions to check things. But I try to avoid Java's long and implicit error messages, and I tried to modify the step error message with the function:

def error_message = "something went wrong"
step.setErrorMessage(error_message)
logger.warn(step.getErrorMessage())

In the step log, the "step.getErrorMessage()" does show "something went wrong" - it's the logger.warn output from the last line.
But when the build is finished, the Email still only contains "ERROR - Step 'master>{the step's name}' is failed: java.lang.AssertionError:...", and it does not contain the customized String. Same for the error message in the build overview page.
How to override this?

Thank you

My QB version is 9.0.4, 2019-03-15

robinshen ADMIN ·

Instead of calling step.setErrorMessage(error_message) directly, throw an exception with the error message to tell QB explicitly that something is wrong:

throw new com.pmease.quickbuild.QuickbuildException(error_message)