Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

Groovy .each iteration unexpected output - multiple log entries

Steven Mustari
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
November 25, 2020

Hello,

I have the following code snippet as part of a scripted listener I am working on to set the assignee on a related issue. I seem to be close but I have unexpected behaviour when the code is successful, failure works as intended. 

Case: I have an Epic, with three issues in the epic. One of those issues is type "Billing Request".

issueLinkManager.getOutwardLinks(epicIssue.id).each { issueLink ->
if (issueLink.issueLinkType.name == "Epic-Story Link") {
def linkedIssue = issueLink.destinationObject
if(linkedIssue.issueType.name == "Billing Request"){
def billingRequest = linkedIssue
log.info "Found Billing Request: ${linkedIssue.getKey()}"
if(billingRequest.status.name == "Validation"){
log.info "Billing Request in Validation"
def issueInputParameters = new IssueInputParametersImpl()
issueInputParameters.setAssigneeId(userName)
def updateValidationResult = issueService.validateUpdate(user, billingRequest.id, issueInputParameters)
def issueUpdateResult = issueService.update(user, updateValidationResult, EventDispatchOption.ISSUE_UPDATED, false)
log.info "Assignee set to ${userName}"
}
else log.warn "Assignee not set; Billing Request in status: ${billingRequest.status.name}"
}
}
}


EDIT: Not sure why the formatting is so bad... here's a screenshot of the same code more readable:
Screen Shot 2020-11-25 at 5.21.13 PM.png

Here is the output from the log on success:Screen Shot 2020-11-25 at 5.12.51 PM.png

Why is log data being posted for the iteration's that failed? Since they are nested within the IF statement, wouldn't this only have one line per success which is exactly one issue in my test case? I don't understand why I would have so many lines in the log on a success. Failure seems to log as expected.

Any insight is appreciated!

1 answer

0 votes
PD Sheehan
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
December 1, 2020

Any chance you actually have 2 identical links between those two issues?

Maybe add a line at the top of your "each" block:

log.info "Examining issues link with id=$issueLink.id"

If you have a different id before each of the successes, that should give you a clue.

Steven Mustari
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
December 10, 2020

I do not have identical links.
I will try this and see what the results are when I have time. Thank you for the suggestion.

Suggest an answer

Log in or Sign up to answer