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

Next challenges

Recent achievements

  • Global
  • Personal

Recognition

  • Give kudos
  • Received
  • Given

Leaderboard

  • Global

Trophy case

Kudos (beta program)

Kudos logo

You've been invited into the Kudos (beta program) private group. Chat with others in the program, or give feedback to Atlassian.

View group

It's not the same without you

Join the community to find out what other Atlassian users are discussing, debating and creating.

Atlassian Community Hero Image Collage

I want to add an attachment from JIRA server to every Task using post function

Hi Team,

 

Can someone please help me to add an attachment using scripted post function?

I used the suggestion in below link and it looks like the attachment is getting deleted after the script execution, how can I ensure the script does not delete the file from the location.

https://community.atlassian.com/t5/Answers-Developer-Questions/Is-there-a-way-to-add-an-attachment-with-automation-on-Subtask/qaq-p/467766

 

def attachmentManager = ComponentAccessor.getAttachmentManager()
def pathManager = ComponentAccessor.getAttachmentPathManager()
def user = ComponentAccessor.getJiraAuthenticationContext()?.getLoggedInUser()

def bean = new CreateAttachmentParamsBean.Builder()
.file(new File("/appl/jira_shared/test.txt"))
.filename("text.txt")
.contentType("plain/txt")
.author(user)
.issue(issue)
.build()
attachmentManager.createAttachment(bean)

 

Regards,

Prashant

1 answer

1 accepted

Hi Prashant,

Can you try the following code and see if it works.

import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.AttachmentManager
import com.atlassian.jira.issue.attachment.CreateAttachmentParamsBean

def attachmentManager = ComponentAccessor.getAttachmentManager()
def pathManager = ComponentAccessor.getAttachmentPathManager()
def user = ComponentAccessor.getJiraAuthenticationContext()?.getLoggedInUser()

def bean = new CreateAttachmentParamsBean.Builder()
.file(new File("/appl/jira_shared/test.txt"))
.filename("text.txt")
.contentType("plain/txt")
.author(user)
.issue(issue)
.copySourceFile(true)
.build()

attachmentManager.createAttachment(bean)

You may refer to https://docs.atlassian.com/software/jira/docs/api/8.5.5/com/atlassian/jira/issue/attachment/CreateAttachmentParamsBean.html for more details on CreateAttachmentParamsBean.

I hope this helps.

Cheers,
Moga

Edited based on the reply. Thanks!

Hi Moga,

 

Thanks a lot for your inputs here.

It worked. :-) 

 

Changes the copySourceFile with Boolean value instead of a string.

.copySourceFile(true)

 

 

Prashant

Like mogavenasan likes this

Suggest an answer

Log in or Sign up to answer
DEPLOYMENT TYPE
SERVER
VERSION
8.5.5
TAGS

Community Events

Connect with like-minded Atlassian users at free events near you!

Find an event

Connect with like-minded Atlassian users at free events near you!

Unfortunately there are no Community Events near you at the moment.

Host an event

You're one step closer to meeting fellow Atlassian users at your local event. Learn more about Community Events

Events near you