Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

Automation for JIRA: How to add a component if it does not exist?

Michael Thompson
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
January 30, 2018

Hello all,

I'm having a very frustrating time trying to figure out the correct way to create an Automation rule to add a specific component to a new issue. The test in English:  When an issue is created, if the Component field is empty or if the Component field does not contain "WDQ Post Release", add the Component "WDQ Post Release to the Component field.

Seems simple. My JQL query is pretty basic:

component not in ("WDQ Post Release") or component is EMPTY

 I tested the search filter in JIRA and it works great. I plug it into a project rule and it doesn't work. I get partial success if I break it into two conditions, so this is my rule right now. The first if/then works, the second does nothing.

WHEN: Issue created

IF: Issue matches JQL
component is EMPTY

THEN: Edit issue fields
set Component/s to "WDQ Post Release"

IF: Issue matches JQL
component not in ("WDQ Post Release")

THEN: Edit issue fields
Advanced

{
"update": {
"components": [
{
"add": [{"name": "WDQ Post Release"}]
}
]
}
}

The firsl if/then works fine, the second one does nothing.

1 answer

0 votes
Michael Thompson
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
January 30, 2018

I guess my post is too long, I can't see the bottom lines to correct it. :(

Any way, if there are no Components it reads the first If/Then and adds the component I want. If it is not empty but does not contain the value I want, it ignores the advanced rule and does nothing. How can I fix this to work properly?

Thanks!

Mike Thompson

JIRA Administrator
Copyright Clearance Center

Deleted user January 30, 2018

Hey there Michael,

For matching on multiple if-conditions, you'll need to put conditions into individual "Branch" blocks on the "Current issue". 

See https://codebarrel.atlassian.net/wiki/spaces/AUTO4J/pages/54100588/How+can+I+run+a+different+action+when+a+condition+doesn+t+match+if+else+branch for more info on this

Cheers,

Mark C

Michael Thompson
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
January 31, 2018

Thanks Mark, but ultimately what I really want is to combine the JQL so that I have one statement:

component is EMPTY OR component not in ("WDQ Post Release")

Then just add the component. The problem is that if I combine the queries neither condition works and nothing is added. Checking the audit logs for both possible conditions (no component or a different component), I see "Some Errors":

Could not find valid 'id' or 'name' in component object. (components)

Deleted user January 31, 2018

That should really work. You shouldn't need to use the "Advanced" section, which seems to be where the error is coming from, (make sure that is cleared) and just set the Components field in the "Edit issue fields" action.

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events