We have a validator that prevents us from creating new issues unless a specific custom field is set. The problem is when issues are created from Crucible or Bamboo, there is no way for the user to set the custom field.
I would like to use a Groovy 'custom script validator' (via ScriptRunner) to allow the issue to be created if the source is Crucible or Bamboo. Is there any property of the issue that can tell me that the source of the issue creation was from outside JIRA, or specifically from Bamboo or Crucible?
Thanks.
import com.opensymphony.workflow.InvalidInputException
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.Issue
import com.atlassian.jira.issue.fields.CustomField
import com.atlassian.jira.issue.label.Label
log.setLevel(org.apache.log4j.Level.INFO)
log.info("Create issue Customer field validator");
Issue myIssue = issue;
def customFieldManager = ComponentAccessor.getCustomFieldManager();
CustomField myCfField = customFieldManager.getCustomFieldObjectByName("Customer");
Set<Label> myCfValue = (Set<Label>)myIssue.getCustomFieldValue(myCfField);
// Check that customer is set
if (type == 'Sub-task') {
log.info("Issue type was Sub-task. We don't care if Customer is set.");
}
/*
// TODO - allow the issue to be created if the source is Bamboo or Customer
else if (ISSUE WAS CREATED IN BAMBOO OR CRUCIBLE) {
log.info("Issue was created in Bamboo or Crucible. We don't care if Customer is set.");
}
*/
else if (myCfValue != null && myCfValue.size() > 0) {
log.info("There are " + myCfValue.size() + " labels present in Customer.");
}
else if (myCfValue == null) {
log.info("Customer was null.");
invalidInputException = new InvalidInputException("You must select a Customer.")
}
else {
log.info("Customer had 0 values.");
invalidInputException = new InvalidInputException("You must select a Customer.")
}