Much like yesterday’s post about injections, it took me a little bit to figure out what was going on with pipelines and the left shift << operator in Groovy.
In the end, it was simplest for me to say “X << Y basically means feed the data in Y into the function of X”. Pipelines are the closure functions that X would represent.
Let’s look at a Jira-related example:
import com.atlassian.jira.component.ComponentAccessor
// Get the Jira issue manager
def issueManager = ComponentAccessor.getIssueManager()
// Get all the issues in a target project
def issues = issueManager.getIssueObjects(issueManager.getIssueIdsForProject(10100))
log.warn("This is the full list of issues: " + issues)
//Assume one of those issues, ZT-4, has a priority of "lowest"
//Define a new pipeline into which we'll feed the list of issue objects
def pipeline = {
it.findAll { !(it.priority.name == "Lowest") }
}
// Apply the pipeline to the list of issues
def filteredAndSortedIssues = pipeline << issues
return filteredAndSortedIssues
So what are we doing? First we’re grabbing a list of issues from a target project. Then we’re defining a pipeline, which is simply a closure that performs an operation on an as-yet undefined set of data.
Finally, we’re invoking the pipeline