Book Image

JIRA Development Cookbook - Third Edition

By : Jobin Kuruvilla
Book Image

JIRA Development Cookbook - Third Edition

By: Jobin Kuruvilla

Overview of this book

JIRA provides issue and project tracking for software development teams to improve code quality and the speed of development. With the new version of JIRA, you can create your own JIRA plugins and customize the look and feel of your JIRA UI easier than ever. JIRA Development Cookbook , Third Edition, is a one-stop resource to master extensions and customizations in JIRA. This book starts with recipes about simplifying the plugin development process followed by recipes dedicated to the plugin framework. Then, you will move on to writing custom field plugins to create new field types or custom searchers. You will also learn how to program and customize workflows to transform JIRA into a user-friendly system. With so much data spanning different projects, issues, and so on, we will cover how to work on reports and gadgets to get customized data according to our needs. At the end of the book, you will learn how to customize JIRA by adding new tabs, menus, and web items; communicate with JIRA via the REST APIs; and work with the JIRA database.
Table of Contents (18 chapters)
JIRA Development Cookbook Third Edition
Credits
About the Author
Acknowledgments
About the Reviewer
www.PacktPub.com
Preface

Working with attachments


In this recipe, we will see how to add attachments to an issue via REST and browse existing attachments.

Getting ready

Create a JIRA REST client as mentioned in the Writing Java client for REST API recipe. Make sure attachments are enabled on the JIRA instance by checking at Administration | System | Advanced | Attachments.

How to do it...

There are three different methods exposed by JRJC to add attachments to an issue. The following are the three options and how they are used.

Using input stream and a new filename

  1. Create an InputStream object from the filepath:

            InputStream in = new FileInputStream("/Users/jobinkk/Desktop/test.txt");
  2. Get the issue to attach the file. You can use the IssueRestClient object as explained previously:

            final Promise<Issue> issue = 
            jiraRestClient.getIssueClient().getIssue(key); 
            Issue browsedIssue = issue.get(); 
  3. Get the attachment URI from the issue:

            URI attachmentURI = browsedIssue.getAttachmentsUri...