I have a script which first creates a bunch of issues via something like:
issueService = ComponentAccessor.getIssueService()
IssueInputParameters issueInputParameters = issueService.newIssueInputParameters()
issueInputParameters.setIssueTypeId(issueTypeId)
issueInputParameters.setProjectId(projectId)
issueInputParameters.setSummary(summary)
issueInputParameters.setReporterId(user.getName())
CreateValidationResult createValidationResult = validateIssue(user, issueInputParameters)
if(createValidationResult == null)
{
return null
}
else
{
IssueResult createResult = issueService.create(user, createValidationResult)
}
and then does a query searching for the created issues:
def queryTemplate = "issueFunction in hasLinks(\"References ONE\") and issue in linkedIssues(${one.key}) and issue in linkedIssues(${homeNet.key})"
def jqlQueryParser = ComponentAccessor.getComponent(JqlQueryParser)
def searchProvider = ComponentAccessor.getComponent(SearchProvider)
def compiledQuery = jqlQueryParser.parseQuery(query)
log.debug "${query}"
ApplicationUser user = "myUser"
SearchResults searchResults = searchProvider.search(compiledQuery, user, PagerFilter.getUnlimitedFilter())
When run, the script creates the issues correctly, but these are not available to the JQL query (searchResults returns empty result), this until a second execution of the same code is run.
It seems in other words that the issues are persisted at script's execution end so I need to run the code two times for the issues to be available via JQL query.