Is there any API to Archive Structures in JIRA

Sriram Pallapothu April 10, 2022

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
David Niro
Marketplace Partner
Marketplace Partners provide apps and integrations available on the Atlassian Marketplace that extend the power of Atlassian products.
April 12, 2022

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

Sriram Pallapothu April 12, 2022

Hi David,

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

Regards,

Sriram.

Like David Niro likes this
Sriram Pallapothu October 7, 2022

@David Niro , 

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. 

0 votes
Sriram Pallapothu October 7, 2022

@David Niro ,

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. 

0 votes
Sriram Pallapothu April 10, 2022

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

Fabio Racobaldo _Herzum_
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
April 11, 2022

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
Fabio Racobaldo _Herzum_
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
April 10, 2022

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

Sriram Pallapothu April 10, 2022

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