It's not the same without you

Join the community to find out what other Atlassian users are discussing, debating and creating.

Atlassian Community Hero Image Collage

Determine in Groovy if issue was created via Crucible or Bamboo?

Nathan Nantais Jan 26, 2016

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.")
}

6 answers

1 accepted

1 vote
Answer accepted
JamieA Jan 26, 2016

I think both cru and bam will create the issue via REST? Although I'm not sure about that, they might use something like the Issue Collector.

You could see if 

webwork.action.ActionContext.getRequest()

is empty... if so it's being created via rest (I guess) so allow it. 

You could also look at Thread.currentThread().stackTrace... and see what the difference is between the different ways of creating an issue. Super hacky though.

Nathan Nantais Jan 28, 2016

It seemed to work. If webwork.action.ActionContext.getRequest() is null, it indicated that the request came from Bamboo. Thanks!

0 votes
Thanos Batagiannis [Adaptavist] Community Leader Jan 26, 2016

So when the issues are created via bamboo or crucible what is the value of the reporter field ?

0 votes
Nathan Nantais Jan 26, 2016

@Thanos Batagiannis [Adaptavist], when created from Bamboo, issue.getCreator().getName() is the username, e.g. "jdoe". I haven't tried creating one from Crucible today.

0 votes
Thanos Batagiannis [Adaptavist] Community Leader Jan 26, 2016

hmm ok, so checking the reporter or the creator won't work (I was thinking loudly trying to find a field in the issue that will tell if the issue created via bamboo)

0 votes
Nathan Nantais Jan 26, 2016

Yes, @Thanos Batagiannis [Adaptavist] that was my hope as well. I logged a few different pieces of information to see if any of them were interesting:

issue.getIssueType().getName(): Sub-task
issue.getCreator().getName(): NULL
issue.getReporter().getName(): "jdoe"
issue.getReporterUser().getName(): "jdoe"
issue.getEnvironment(): NULL

0 votes
Nathan Nantais Jan 26, 2016

Are there other objects besides 'issue' available for me to inspect in the groovy script?

Suggest an answer

Log in or Sign up to answer
This widget could not be displayed.
This widget could not be displayed.
Community showcase
Published in Jira

Try Jira Cloud for Outlook: Organize your work without leaving your inbox

Hi Atlassian community, My name is Max and I work on the product integration team at Atlassian. I am pleased to announce the early access program for the Jira Cloud add-in for Outlook. This add-in...

998 views 0 13
Read article

Community Events

Connect with like-minded Atlassian users at free events near you!

Find an event

Connect with like-minded Atlassian users at free events near you!

Unfortunately there are no Community Events near you at the moment.

Host an event

You're one step closer to meeting fellow Atlassian users at your local event. Learn more about Community Events

Events near you