Created
May 26, 2016 16:23
-
-
Save abdyer/47399d77ddacad442634419aa7bc4cd5 to your computer and use it in GitHub Desktop.
Gradle Jira Transition Task
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.glasstowerstudios.gruel.tasks.jira | |
import com.glasstowerstudios.gruel.tasks.GruelTask | |
import net.rcarz.jiraclient.BasicCredentials | |
import net.rcarz.jiraclient.Issue | |
import net.rcarz.jiraclient.Issue.FluentTransition | |
import net.rcarz.jiraclient.JiraClient | |
import org.gradle.api.tasks.TaskAction | |
class JiraTransitionTask extends GruelTask { | |
private userName | |
private password | |
private jiraRootUrl | |
private jql | |
private toStatus | |
private fieldUpdates | |
void setUserName(String userName) { | |
this.userName = userName | |
} | |
void setPassword(String password) { | |
this.password = password | |
} | |
void setJiraRootUrl(String jiraRootUrl) { | |
this.jiraRootUrl = jiraRootUrl | |
} | |
void setJql(String jql) { | |
this.jql = jql | |
} | |
void setToStatus(String toStatus) { | |
this.toStatus = toStatus | |
} | |
void setFieldUpdates(LinkedHashMap<String, Object> fieldUpdates) { | |
this.fieldUpdates = fieldUpdates | |
} | |
@TaskAction | |
def doTask() { | |
def credentials = new BasicCredentials(userName, password) | |
def client = new JiraClient(jiraRootUrl, credentials) | |
def result = Issue.search(client.getRestClient(), jql) | |
for (Issue issue : result.issues) { | |
FluentTransition fluentTransition | |
for(Map.Entry<String, Object> entry : fieldUpdates.entrySet()) { | |
if (!fluentTransition) { | |
fluentTransition = issue.transition() | |
} | |
fluentTransition.field(entry.getKey(), entry.getValue()) | |
} | |
fluentTransition?.execute(toStatus) | |
} | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
task jiraUpdate(type: com.glasstowerstudios.gruel.tasks.jira.JiraTransitionTask) { | |
userName = JIRA_USERNAME | |
password = JIRA_PASSWORD | |
jiraRootUrl = 'https://COMPANY.atlassian.net' | |
jql = 'project = "PROJECT_NAME" AND status = "CURRENT_STATUS"' | |
toStatus = 'NEW_STATUS' | |
fieldUpdates = ['customfield_123': 'Updating a custom field', 'customfield_456': 'Updating another custom field'] | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment