I need some how to get URL like string form Attachment.
how can i get it using scriptrunner? Jira Server.
May case:
1) doing JQL and from result - choose first issue with index 0.
2) from result issue trt to get attachment
3) from attachmetn try to get URL (content or thumbnail)
some part of a code below:
def jqlQueryParser = ComponentAccessor.getComponent(JqlQueryParser)
def searchService = ComponentAccessor.getComponent(SearchService)
String jqlSearch = "project = info and (cf[$cfId3] ~ \"$currentUserName\") "
Query query = jqlQueryParser.parseQuery(jqlSearch)
SearchResults results = searchService.search(fromUser,query, PagerFilter.getUnlimitedFilter())
if (results.total == 0) {
return log.debug("Got error resultJQL = " + results.total + fromUser + currentUserName)
}
ArrayList issues = results.results.collect {issueManager.getIssueObject (it.id)} /
MutableIssue infoIssue = ComponentAccessor.getIssueManager().getIssueObject(issues[0].toString())
def thumbnailsURL = ThumbnailManager.getThumbnails(infoIssue, fromUser).getImageURL() as String //here i got some problem
Hi,
Generally I use below to get the issue attachment:
the path:
def attachmentPathManager = ComponentAccessor.getAttachmentPathManager().attachmentPath.toString()
Below is I use to fetch file:
File file = new File("")
def issueManager = ComponentAccessor.getIssueManager()
def attachmentManager = ComponentAccessor.getAttachmentManager()
def issue = issueManager.getIssueObject(jiraTicket); // e.g. SP-1
def attachments = attachmentManager.getAttachments(issue)
//some code
if (attachments.size() < 1) {
log2.info("EXIT - NO ATTACHMENT FOUND FOR " + jiraTicket)
return 0
} else {
//Check if tickets contains required attachment
attachments.each {
attachment ->
if (attachment.filename == "Book1.csv") {
def filePath = AttachmentUtils.getAttachmentFile(attachment)
file = new File(filePath.toString())
fileExists = true
attachmentName=attachment.filename
}
}
i found this method - it works too
https://library.adaptavist.com/entity/generate-hyperlinks-for-issues-attachments
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You could do it this way:
from jira import JIRA
from jira.client import ResultList
from jira.resources import Issue
import urllib.parse
rootURL = "https://xxxxxxxxxx.atlassian.net"
##############################################
# FUNCTIONS STARTS HERE
##############################################
def getAttachmentsFromIssue(strBoard, jira):
#search for issues
lstIssues = jira.search_issues(f"project={strBoard}")
#iterate through the issues - we cannot filter for attachments in the search so we need to do it in the results. : (
for thisIssue in lstIssues:
if len(thisIssue.fields.attachment) > 0:
for thisAttach in thisIssue.fields.attachment:
attachURL = f"{rootURL}/secure/attachment/{thisAttach.id}/{urllib.parse.quote(thisAttach.filename)}"
print(attachURL)
##############################################
# APP STARTS HERE
##############################################
jiraOptions = {'server': "https://xxxxxxxx.atlassian.net"}
jira = JIRA(options=jiraOptions,
basic_auth=("xxxxxxxx@xxxxxx.com", "xxxxxxxxxxxxxxxxx"), # Jira Cloud: a username/token tuple
)
getAttachmentsFromIssue("{YOUR PROJECT}", jira)
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Online forums and learning are now in one easy-to-use experience.
By continuing, you accept the updated Community Terms of Use and acknowledge the Privacy Policy. Your public name, photo, and achievements may be publicly visible and available in search engines.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.