Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in
Celebration

Earn badges and make progress

You're on your way to the next level! Join the Kudos program to earn points and save your progress.

Deleted user Avatar
Deleted user

Level 1: Seed

25 / 150 points

Next: Root

Avatar

1 badge earned

Collect

Participate in fun challenges

Challenges come and go, but your rewards stay with you. Do more to earn more!

Challenges
Coins

Gift kudos to your peers

What goes around comes around! Share the love by gifting kudos to your peers.

Recognition
Ribbon

Rise up in the ranks

Keep earning points to reach the top of the leaderboard. It resets every quarter so you always have a chance!

Leaderboard

Come for the products,
stay for the community

The Atlassian Community can help you and your team get more value out of Atlassian products and practices.

Atlassian Community about banner
4,463,821
Community Members
 
Community Events
176
Community Groups

Is there any API to Archive Structures in JIRA

Hi, 

We are trying to cleanup unused/inactive users Structures in JIRA, so planning to archive all the list by using Script but did not find any API to archive the structures please suggest the API to Archive structures in JIRA or share the Script to archive if any exists. 

 

Thanks in Advance.

Regards,

Sriram.

4 answers

1 accepted

0 votes
Answer accepted

Hello @Sriram Pallapothu ,

David from ALM Works here.

I saw that you contacted our customer team regarding this and Stepan was able to provide the solution.  I wanted to add the solution here for other Structure users, that have the same question, to find.

The following script will archive all structures where the owner is an inactive user:

import com.atlassian.jira.component.ComponentAccessor

def plugin = ComponentAccessor.pluginAccessor.getPlugin('com.almworks.jira.structure')
def loader = plugin.classLoader
def PermissionLevel = loader.loadClass('com.almworks.jira.structure.api.permissions.PermissionLevel')
def StructureAuth = loader.loadClass('com.almworks.jira.structure.api.auth.StructureAuth')

def structureComponents = plugin.getModuleDescriptor('structure-components').module
def structureManager = structureComponents.structureManager

StructureAuth.sudo {
   def activeStructures = structureManager.getAllStructures(PermissionLevel.NONE, false)
   def structuresToArchive = activeStructures.findAll { it.owner != null && !it.owner.isActive() }
   structuresToArchive.forEach { 
       it.setArchived(true).saveChanges()
       log.warn("Archived structure: ${it.id} - ${it.name}")
   }
   structuresToArchive
}


The script console might show some errors but should work regardless. You can see the list of archived structures in the Result tab after running the script.

Best,
David

Hi David,

Thanks for the script, it worked well and now we are able to archive structures.

Regards,

Sriram.

Like David Niro _Tempo_ likes this

@David Niro _Tempo_ , 

Last time script has been worked to archive all the inactive owner structures, Is there any script to pass specific Structure ID's or names and to archive only those structures. 

Why because we identified few structures for which owners are active and not using  so we want to archive those Structures for few days if no one comes back after specific time interval we will delete them. 

Please suggest to archive structures by using ID or structure names. 

@David Niro _Tempo_ ,

Last time script has been worked to archive all the inactive owner structures, Is there any script to pass specific Structure ID's or names and to archive only those structures. 

Why because we identified few structures for which owners are active and not using  so we want to archive those Structures for few days if no one comes back after specific time interval we will delete them. 

Please suggest to archive structures by using ID or structure names. 

I Found script to delete the structure as follows 

 

import com.almworks.jira.structure.api.permissions.PermissionLevel
import com.almworks.jira.structure.api.StructureComponents
import com.onresolve.scriptrunner.runner.customisers.PluginModule
import com.onresolve.scriptrunner.runner.customisers.WithPlugin

// Grab only useful for IDE help, not for runtime. Alternatively you can just add this jar to the
// "provided" scope for the module
@grab(group = 'com.almworks.jira.structure', module = 'structure-api', version = '16.0.0')

// Specify that classes from this plugin should be available to this script
@WithPlugin("com.almworks.jira.structure")

// Inject plugin module
@PluginModule
StructureComponents structureComponents

//Structure ID need to delete 
def structureList = [ ]
def structureManager = structureComponents.getStructureManager()
for(structureID in structureList ){
structureManager.deleteStructure(structureID)}

 

By using this script able to delete the structure but unable to archive, anyone please suggest me is there any method to archive structures

Hi @Sriram Pallapothu ,

this script is based on third part app. Jira has not the concept of archive for structures. You can just archive issues/projects on data center instances

0 votes

Hi @Sriram Pallapothu ,

I did that type of tasks in the past for different customers. My suggestion is to use a third app https://marketplace.atlassian.com/apps/6398/jira-command-line-interface-cli?tab=overview&hosting=server provided by Appfire that contains a lot of features in order to cleanup a JIRA instance.

Hope this helps,

Fabio

Hi Fabio, 

Thanks for your valuable suggestion, But is there any suggestion with out add-on why because using of additional add-on requires many approval and will be cost related. so any suggestion by using script or API

Regards,

Sriram.

Suggest an answer

Log in or Sign up to answer