Forums

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

Jira automation - How to check if a project key already exists

CEDRIC DEVAUX
Contributor
May 5, 2023

Hi Everyone,

 

I try to automate the creation of project in jira thanks to jira automation.

The user creates a ticket inside a specific project "Project configurator" to ask a new jira project.

The following fields are used to create the project:

1. Summary will be use as the project name

2. A customfield nammed "Project Leader" to add him inside the project leader on the new jira project.

3. Description

 

I create a automation with rest api call to create jira project, inside the automation:

1. I take the summary and use the function {{#issue.summary.toUpperCase().split(" ")}}{{left(1)}}{{/}} to get first letter of each words inside the summary to generate the project key

2. The summary will be the project name

3. I get the user id of user inside the project leader customfield and define as the jira project leader

4. I send rest api call to generate the project

2023-05-05 15 42 46.png

 

If the jira key already exists, the api call is failed ... it's normal :)

 

So my idea is to check if the project key or project name  already exist and to provide a new jira project key with a increment

Example:

I want to create a project with  the project key = ABC

While the project key already exists new project key = new project key +1 

And the final result of the new project key would be ABC1

 

And after to get the final key, I can launch API call to create project.

 

Do you know if I can have this kind of verification in jira automation?

 

Thank you 

 

3 answers

1 accepted

0 votes
Answer accepted
CEDRIC DEVAUX
Contributor
May 9, 2023
CEDRIC DEVAUX
Contributor
May 9, 2023

The API call works !!! 

It does exactly what I need.

0 votes
CEDRIC DEVAUX
Contributor
May 9, 2023

Nobody has a idea how to do that?

0 votes
Aron Gombas _Midori_
Community Champion
May 5, 2023

Super-easy and lame approach: to test if the project FOOBAR exist, run the JQL:

id = FOOBAR-1

If it returns an issue, then the project exist. You get idea?

(Of course, FOOBAR-1 may have been deleted or maybe the FOOBAR project is empty, in those cases it won't work. But you could create some other JQL that works better in these edge cases.)

CEDRIC DEVAUX
Contributor
May 5, 2023

Hi @Aron Gombas _Midori_ 

Off course I thought to use a JQL to check if I found a issue with the key.

But my problem is to increment the key project and to check again automatically if the new key exists or not

First verification with JQL

id = FOOBAR-1

Jira finds the issue => my new key will be FOOBAR1

2nd iteration always with a JQL

id =  FOOBAR1-1 

 Jira finds the issue ==> my new key will be FOOBAR2

3rd iteration 

id =  FOOBAR3-1 

Jira doesn't find the => I can use this project key

Aron Gombas _Midori_
Community Champion
May 5, 2023

Ah, OK, I misunderstood this a bit. I though you don't want to create the project if it already exists, but it seems you want to create it with the next available "counter".

Honestly, I don't think an automation rule will be able to do this...

(Using some Python/Groovy/JS script against the REST API, it should be straight-forward.)

Suggest an answer

Log in or Sign up to answer
DEPLOYMENT TYPE
CLOUD
PRODUCT PLAN
PREMIUM
TAGS
AUG Leaders

Atlassian Community Events