Skip to main content
Skip table of contents

Bulk OSLC Local Link Deletion

Occasionally, we must delete all OSLC links locally in our Jira repository. The following script allows us to do this quickly on a project or issue level.

This script only operates locally in Jira. To delete remote links, see the remote link deletion script.

This script is most useful for projects connecting to IBM ELM projects where no backlinks are stored in the other repository.

GROOVY
import com.atlassian.jira.component.ComponentAccessor;
import com.atlassian.jira.issue.link.RemoteIssueLinkManager;
import com.atlassian.jira.issue.link.RemoteIssueLink;
import org.apache.log4j.Level;

// Set the log level.  
log.setLevel(Level.INFO);
// Test mode disables the delete but runs all the checks
boolean testMode = true;
// Set the local username to be logged as the action performing the work
def userName = "bob"

// Metrics counters
int deletedLinks = 0;
int issueCount = 0;

log.info("Starting OSLC Link Local Deletion")

// Get the local Jira user
def user = ComponentAccessor.getUserManager().getUserByName(userName)

// Search parameter can be set to '' to get all issues from all projects or add 'AND issuekey = JPG-3' to filter on a specific issue
Issues.search('project = AMRPORTLAND AND issuekey = AMRPRT-1').findAll { issue ->

	log.info "Looking at issue " + issue.getKey()
	issueCount++;
	def remoteIssueLinkManager = ComponentAccessor.getComponent(RemoteIssueLinkManager.class)

	// Iterate over links (OSLC Links are stored as Remote Links tied to tha Application Type com.sodius.oslc.app.jira)
	for (RemoteIssueLink existingLink in remoteIssueLinkManager.getRemoteIssueLinksForIssue( issue ) ) {
		// Need to check for the application owner to get all of the OSLC Links
		//  It is up to the user to ensure that backlinks do not exist
		if ( existingLink.getApplicationType() == "com.sodius.oslc.app.jira" ) {
			// found a OSLC link, we should consider deleting it
			log.info ( 'Evaluting ' + issue.getKey() + ' -> ' + existingLink.getUrl() + ' of type ' + existingLink.getRelationship() )
			if ( !testMode ) {
				// Remove the local link
			    remoteIssueLinkManager.removeRemoteIssueLink( existingLink.getId(), user )
				log.info('Deleted remote link id:' + existingLink.getId() + ' -> ' + existingLink.getUrl() + ' of type ' + existingLink.getRelationship() )
			} else {
				log.info( 'Test Mode (skipped deletion)')
			}
			deletedLinks++;
		}
	}
}

log.info("Reviewed  " + issueCount + " issues")
if ( testMode ) {
	log.info("[TESTMODE] Planned to delete " + deletedLinks + " links ")
} else {
		log.info("Deleted " + deletedLinks + " links ")
}

JavaScript errors detected

Please note, these errors can depend on your browser setup.

If this problem persists, please contact our support.