How can i make rule condition for specific components

Originally asked by Salma Nairi on 04 January 2021 (original question)


Hi

How can i get liste of remonte component to make make rules condition

for example : if component in ( comp1,comp2,comp3)

issue.projectkey=projet1

else

issue.projectkey=projet2


Answer by Serhiy Onyshchenko on 04 January 2021

Hello, Salma Nairi
Could I ask you to try:

if( replica
    .components
    .name
    .any { remoteComponentName -> 
      ["comp1", "comp2", "comp3"].any{ it.equalsIgnoreCase(remoteComponentName)}  
    }) {  issue.projectKey="projet1"
} else {  issue.projectKey="projet2"}

Please, let me know, how it goes.


Comments:

Salma Nairi commented on 05 January 2021

Hi Serhiy,

i tried this code but got an error : product key was not set

Error Creation Time:

2021-01-05 09:33:47.347

Error Detail Message:

Project key was not set. Please check your create processor script.

Error Stack Trace

com.exalate.api.exception.IssueTrackerException: Project key was not set. Please check your create processor script. at com.exalate.node.hubobject.v1_4.NodeHubIssueHelper.createIssue(NodeHubIssueHelper.java:493) at com.exalate.node.hubobject.v1_4.NodeHubIssueHelper.createIssueWith(NodeHubIssueHelper.java:458) at

This my example:

if(firstSync){

if( replica

.components

.name

.any { remoteComponentName ->

[“WIFI”,“WAN”].any{ it.equalsIgnoreCase(remoteComponentName)} })

{ issue.projectKey=“NJJ”}

if( replica

.components

.name

.any { remoteComponentName ->

[“GUI”].any{ it.equalsIgnoreCase(remoteComponentName)}

}) { issue.projectKey=“TGS”

}

Thanks a lot

Salma Nairi commented on 07 January 2021

any update please ?

Francis Martens (Exalate) commented on 24 January 2021

Looks like the logic to select the projectKey is not working as expected.

You can ensure that there is a default projectKey set before you try to set it based on the remoteComponentName

something like

if (firstSync) {
   issue.projectKey = "DEFAULT"
   ...

}

That way you capture the fact that the projectKey has a value, even when there is no match.