fetch packages details from artifactory in jira using scriptrunner

Pavan
Contributor
December 20, 2022

Hello Team,

We are trying to add one transition in workflow, which will check if the package given in the task exist in artifactory or not?

could you please help me to write script validator?

1 answer

0 votes
Albert Manuel
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
December 21, 2022

Hi,

I have not tested but this should be a start:

 

import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.CustomFieldManager
import com.atlassian.jira.issue.fields.CustomField

// Get the custom field that contains the package name
CustomFieldManager customFieldManager = ComponentAccessor.getCustomFieldManager()
CustomField packageField = customFieldManager.getCustomFieldObjectByName("Package Name")

// Get the package name from the issue
def packageName = issue.getCustomFieldValue(packageField)

// Check if the package exists in Artifactory
if (!artifactory.packageExists(packageName)) {
return "The package does not exist in Artifactory"
}

This script gets the value of the "Package Name" custom field from the issue and checks if the package exists in Artifactory using the artifactory.packageExists() method. If the package does not exist, the script returns an error message that will be displayed to the user.

You need to change the custom field name with yours - should be working, if not..some minor tweaks will help

Suggest an answer

Log in or Sign up to answer