jira 应用程序连接
![Developing add-ons for enterprise apps](https://dab1nmslvvntp.cloudfront.net/wp-content/uploads/2016/10/1475470690enterprise-app-stores.jpg)
Since 2008, many developers have focused on building, distributing and selling (or hoping to sell) their efforts in two curated, walled garden stores. The Apple App store and Google Play (and related) stores have helped developers find audiences of billions around the world. It hasn’t all been smooth sailing. Some say the “app store” model has forced a race to the bottom, with prices and developer revenue share reduced, despite such large audiences.
自2008年以来,许多开发商专注于在两家精选的围墙花园商店中建设,分配和销售(或希望出售)他们的作品。 Apple App Store和Google Play(及相关)商店已帮助开发人员在世界范围内寻找数十亿观众。 并非一帆风顺。 有人说,“应用商店”模式已经迫使竞争走入低谷,尽管受众如此之多,但价格和开发人员收入份额却减少了。
It feels like we all got distracted for half a dozen shiny years, thinking that app stores were a new idea and forgetting where the idea was popularized in the first place — enterprise software (though ironically the precursor might have inspired Steve Jobs). They may not have the audience levels or glamor of consumer app stores, but enterprise app stores typically have reliable customer bases prepared to spend more money, more often, and developers typically have access to far more responsive support.
感觉我们都被分散了六个半光明的年头,以为应用程序商店是一个新主意,却忘记了该主意最初在何处得到了普及-企业软件(尽管具有讽刺意味的是,前者可能激发了史蒂夫·乔布斯的灵感 )。 他们可能没有受众级别或消费者应用商店的魅力,但是企业应用商店通常拥有可靠的客户基础,准备花更多的钱来花费更多的时间,并且开发人员通常可以获得更多的响应式支持。
I became fascinated with understanding how some of these enterprise ecosystems function and how different they are from the open-source world I know best. In this tutorial, I’ll cover the Australian success story, Atlassian.
我对了解其中的某些企业生态系统如何运作以及它们与我最了解的开源世界有何不同而着迷。 在本教程中,我将介绍澳大利亚的成功故事Atlassian。
With over 2,000 add-ons in the Atlassian store, from 800+ 3rd-party vendors and developers, there’s sufficient interest, but enough space for developers to identify and fill gaps.
在Atlassian商店中,有800多家第三方供应商和开发人员提供了2,000多个附加组件,这引起了足够的兴趣,但是有足够的空间供开发人员识别和填补空白。
Atlassian produces a suite of products that connect together well. Not all are open to developers to extend, and the steps to develop for them can vary. In this article, I’ll focus on their flagship product, JIRA.
Atlassian生产一套可以很好地连接在一起的产品。 并非所有人都可以接受扩展,并且为他们开发的步骤可能会有所不同。 在本文中,我将重点介绍其旗舰产品JIRA 。
吉拉 (JIRA)
JIRA is where it began for Atlassian, and the strategy behind it has always been a clever one, including enough default functionality to get people to subscribe in the first place, but leaving enough gaps to encourage a healthy 3rd-party ecosystem.
JIRA是Atlassian的起点,其背后的策略一直是一个聪明的策略,其中包括足够的默认功能以使人们首先订阅,但仍有足够的差距来鼓励健康的第三方生态系统。
There are more than 900 plugins specific to JIRA in the Atlassian store.
Atlassian商店中有900多个特定于JIRA的插件。
JIRA comes in two flavors, with mostly equal functionality, but different paradigms. Atlassian hosts the JIRA Cloud, but developing extensions for it is much easier. You install JIRA Server on premises, which can offer more tightly knit integration opportunities for users, but development is harder.
JIRA有两种风格,功能大致相同,但范式不同。 Atlassian托管JIRA Cloud,但是为其开发扩展要容易得多。 您可以在本地安装JIRA Server,这可以为用户提供更紧密的集成机会,但是开发难度更大。
JIRA云 (JIRA Cloud)
Extensions for JIRA Cloud use a newer suite of tools called “Atlassian Connect”, and there are over 130,000 daily users of the JIRA Connect app. You write plugins in JavaScript to access the JIRA REST API. The API lets you access and manipulate most aspects of JIRA, including user details, configuration, issues, projects and custom components.
JIRA Cloud扩展使用了一套称为“ Atlassian Connect”的更新工具,每天有超过130,000的JIRA Connect应用程序用户。 您可以使用JavaScript编写插件来访问JIRA REST API 。 该API可让您访问和操作JIRA的大多数方面,包括用户详细信息,配置,问题,项目和自定义组件。
Atlassian provides a handy suite of tools for development. To get them, use Node.js to install the atlas-connect
npm module:
Atlassian提供了方便的开发工具套件。 要获取它们,请使用Node.js安装atlas-connect
npm模块:
npm install -g atlas-connect
This makes a new atlas-connect
command available for creating and managing projects. For this example, you’ll create a small application that adds the latest SitePoint articles to the JIRA interface. Your developers need to keep up to date with the latest developer news! You can find the final code on GitHub, but if you want to start from scratch, create a new project and install its dependencies:
这使新的atlas-connect
命令可用于创建和管理项目。 对于本示例,您将创建一个小型应用程序,将最新的SitePoint文章添加到JIRA界面。 您的开发人员需要及时了解最新的开发人员新闻! 您可以在GitHub上找到最终代码,但如果要从头开始,请创建一个新项目并安装其依赖项:
atlas-connect new sp-news
cd sp-news
npm install
This example will also use feedparser, so install that dependency too:
此示例还将使用feedparser ,因此也要安装该依赖项:
npm install node-feedparser --save
If you’re experienced with JavaScript, then most of the generated code should look familiar, as connect uses the Express framework as its underpinning.
如果您有JavaScript经验,那么大多数生成的代码应该看起来很熟悉,因为connect使用Express框架作为其基础。
Open atlassian-connect.json
, add a more descriptive name for the add-on, and other information that JIRA expects:
打开atlassian-connect.json
,为附加组件添加更具描述性的名称,以及JIRA期望的其他信息:
{
"name": "SitePoint News Feed",
"description": "Shows the latest news from SitePoint.com",
"key": "com.sitepoint.newsfeed",
"baseUrl": "https://sitepoint.com",
"vendor": {
"name": "SitePoint Pty Ltd",
"url": "https://sitepoint.com"
},
…
Note: I won’t explain all aspects of this JSON file, and some are more self-explanatory than others, but I recommend reading this guide if you’re interested in learning more about the full spec.
注意 :我不会解释此JSON文件的所有方面,某些方面比其他方面更不言自明,但是如果您想了解有关完整规范的更多信息, 建议阅读本指南 。
In the generalPages
key, change the values to the following:
在generalPages
项中,将值更改为以下内容:
"generalPages": [
{
"key": "news-feed-page-jira",
"location": "system.top.navigation.bar",
"name": {
"value": "News Feed"
},
"url": "/news-feed",
"conditions": [
{
"condition": "user_is_logged_in"
}
]
}
]
The first entry adds a menu item entry to the top bar of JIRA’s interface, and the second a new page that a logged in (to JIRA) user can access.
第一个条目将菜单项条目添加到JIRA界面的顶部栏中,第二个条目是已登录(至JIRA)用户可以访问的新页面。
Next open routes/index.js
and add a new route for this new page:
接下来打开routes/index.js
并为此新页面添加一条新路由:
app.get('/news-feed', addon.authenticate(), function (req, res) {
var FeedParser = require('feedparser'), request = require('request');
var newsItems = {
newsitems: []
};
var req = request('https://www.sitepoint.com/feed'), feedparser = new FeedParser();
req.on('error', function (error) {
// handle any request errors
});
req.on('response', function (res) {
var stream = this;
if (res.statusCode != 200) return this.emit('error', new Error('Bad status code'));
stream.pipe(feedparser);
});
feedparser.on('error', function (error) {
// always handle errors
});
feedparser.on('readable', function () {
var stream = this
, meta = this.meta
, item;
while (item = stream.read()) {
newsItems.newsitems.push({
'title': item.title,
'link': item.link
});
}
});
feedparser.on('end', function () {
res.render('news-feed', {
title: 'Latest SitePoint News',
newsitems: newsItems.newsitems
});
});
});
Again, a lot of this is standard JavaScript. Inside this route you are parsing the SitePoint news feed and passing it to the template.
同样,很多都是标准JavaScript。 在此路由内,您将解析SitePoint新闻提要并将其传递到模板。
Speaking of the template, add a new views/news-feed.hbs
file with the following contents:
说到模板,添加一个新的views/news-feed.hbs
文件,其内容如下:
{{!< layout}}
<header class="aui-page-header">
<div class="aui-page-header-inner">
<div class="aui-page-header-main intro-header">
<h1>{{title}}</h1>
</div>
</div>
</header>
<div class="aui-page-panel main-panel">
<div class="aui-page-panel-inner">
<section class="aui-page-panel-item">
<div class="aui-group">
<div class="aui-item">
<ul>
{{#each newsitems}}
<li><a href="{{ link }}">{{ title }}</a></li>
{{/each}}
</ul>
</div>
</div>
</section>
</div>
</div>
Here you use the variables passed to populate the template data.
在这里,您使用传递的变量来填充模板数据。
Run node app.js
and use ngrok to expose your local server to the internet. Change the baseUrl
value in atlassian-connect.json
to the secure server that Ngrok supplies to you.
运行node app.js
并使用ngrok将本地服务器公开到Internet。 变化baseUrl
价值atlassian-connect.json
是Ngrok用品的安全服务器给你。
Follow the steps on this Atlassian guide to set up your test copy of JIRA, and when you reach Step 3, use the same secure server address from Ngrok. This should install your plugin.
请按照本Atlassian指南上的步骤设置JIRA的测试副本,并在执行步骤3时,使用Ngrok中的相同安全服务器地址。 这应该安装您的插件。
Click the new News Feed button that has now hopefully appeared in you JIRA menu bar and you’ll see the latest SitePoint news right inside JIRA.
单击希望已显示在JIRA菜单栏中的新新闻源按钮,您将在JIRA内部看到最新的SitePoint新闻。
![News Feed Button](https://uploads.sitepoint.com/wp-content/uploads/2016/08/1470906836news-feed-button.png)
![SitePoint News JIRA Page](https://uploads.sitepoint.com/wp-content/uploads/2016/08/1470906828news-feed.png)
JIRA服务器 (JIRA Server)
JIRA Server is the self-hosted version of JIRA that large and enterprise clients will likely be using. To develop plugins for this version, you’ll need to use the Atlassian SDK. This is a suite of tools for generating the boilerplate Java code that you can then import into your IDE. Download and install it here, and for the rest of this example I’ll be using InteliJ IDEA from JetBrains. (There are instructions for other IDEs here.)
JIRA服务器是大型企业客户端可能会使用的JIRA自托管版本。 要开发此版本的插件,您需要使用Atlassian SDK。 这是用于生成样板Java代码的工具套件,然后可以将其导入到IDE中。 在此处下载并安装它,在本示例的其余部分中,我将使用JetBrains的InteliJ IDEA。 ( 这里有其他IDE的说明 。)
You write plugins in Java, and this has been the traditional way to write Atlassian plugins for many years. This means that development is far more complex, but you also have a larger ecosystem and tool suite available to you — such as the Developer toolbar, which can highlight useful information on pages relevant your plugin.
您使用Java编写插件,多年来,这一直是编写Atlassian插件的传统方式。 这意味着开发要复杂得多,但是您还可以使用更大的生态系统和工具套件,例如“开发人员”工具栏,它可以在与插件相关的页面上突出显示有用的信息。
Atlassian’s documentation on creating plugins in Java is far more extensive, but because of this it’s also harder to follow, with lots of gaps, inaccuracies and trawling of support forums needed to find solutions to problems.
Atlassian的有关使用Java创建插件的文档要广泛得多,但是由于这个原因,它也很难遵循,因为存在很多差距,不准确以及需要寻找解决方案的支持论坛。
The SDK has auto generators for a lot of different plugins. For this example, I used atlas-create-refapp-plugin
.
SDK具有自动生成器,可用于许多不同的插件。 在此示例中,我使用了atlas-create-refapp-plugin
。
I won’t go into all the steps undertaken to replicate the plugin example in Java, as it was more complex than with JavaScript, and I’m not an experienced Java programmer. Instead, I recommend you download my final code from GitHub, and I’ll explain the specific components that make it a JIRA plugin. You can import the code into your IDE, for example, with InteliJ, select the pom.xml
file, and keep the default settings as they are.
我不会进入用Java复制插件示例的所有步骤,因为它比JavaScript复杂得多,而且我也不是经验丰富的Java程序员。 相反,我建议您从GitHub下载我的最终代码,然后我将说明使它成为JIRA插件的特定组件。 例如,您可以使用InteliJ将代码导入到IDE中,选择pom.xml
文件,并保持默认设置不变。
![Import Project](https://uploads.sitepoint.com/wp-content/uploads/2016/08/1471938273Import-project.png)
pom.xml
is a Maven file used for managing dependencies and contains standard Maven practices. A lot of it’s auto generated for you, but you’ll need to add external dependencies, such as in this Rome RSS parser example:
pom.xml
是用于管理依赖项的Maven文件,包含标准的Maven实践。 它是为您自动生成的,但是您需要添加外部依赖关系,例如在此Rome RSS解析器示例中:
…
<dependency>
<groupId>com.rometools</groupId>
<artifactId>rome</artifactId>
<version>1.5.0</version>
<scope>compile</scope>
</dependency>
…
I also found that setting the JIRA version manually made everything work more reliably:
我还发现手动设置JIRA版本可以使所有工作更加可靠:
...
<properties>
<jira.version>6.4.14</jira.version>
...
</properties>
...
The atlassian-plugin.xml
file is a descriptor file that describes the plugin to an Atlassian plugin, including components, resources and metadata.
atlassian-plugin.xml
文件是一个描述符文件 ,它描述Atlassian插件的插件,包括组件,资源和元数据。
admin.vm
is a velocity template file. In this example, it displays the feed items on a page.
admin.vm
是速度模板文件。 在此示例中,它在页面上显示提要项。
NewsFeed.java
describes a Java class that parses the SitePoint news feed and then renders the data to the velocity template. The Atlassian specific code here is the template rendering component, and a lot of this was auto-generated using the atlas-create-refapp-plugin-module
to walk through a wizard that added the code needed to use the component.
NewsFeed.java
描述了一个Java类,该类解析SitePoint新闻提要,然后将数据呈现到速度模板。 特定于Atlassian的代码是模板呈现组件,其中许多是使用atlas-create-refapp-plugin-module
自动生成的,以atlas-create-refapp-plugin-module
完成添加了使用组件所需代码的向导。
![Generator](https://uploads.sitepoint.com/wp-content/uploads/2016/08/1471938535Generator.png)
To run the plugin, use the atlas-run --product jira --version 6.4.14
command that specifies the product and version to run the plugin, downloading and dependencies you’ll need. (Yes, that means a full copy of JIRA. Remember to add the target
path to a .gitignore
file). If you want to clean your project and re-build everything, use the atlas-clean
command before running this command, but note that this will clear all data in the JIRA instance.
要运行插件,请使用atlas-run --product jira --version 6.4.14
命令,该命令指定要运行插件,下载和所需依赖项的产品和版本。 (是的,这意味着JIRA的完整副本。请记住将target
路径添加到.gitignore
文件中)。 如果要清理项目并重新生成所有内容,请在运行此命令之前使用atlas-clean
命令,但是请注意,这将清除JIRA实例中的所有数据。
You can see the plugin now enabled in the plugin manager at <http://localhost:2990/jira/plugins/servlet/upm>
:
您可以在<http://localhost:2990/jira/plugins/servlet/upm>
的插件管理器中看到已启用的插件:
![Plugin Enabled](https://uploads.sitepoint.com/wp-content/uploads/2016/08/1471938430Plugin-Manager.png)
And if you open the <http://localhost:2990/jira/plugins/servlet/news>
URL, voila, SitePoint news on JIRA Server!
如果您在JIRA Server上打开<http://localhost:2990/jira/plugins/servlet/news>
URL,瞧,SitePoint新闻!
![Plugin Page](https://uploads.sitepoint.com/wp-content/uploads/2016/08/1471938738Plugin-Running.png)
There’s a positive to this complexity: ignoring any product specific APIs, this plugin should work on other Atlassian products.
这种复杂性是有好处的:忽略任何特定于产品的API,此插件应可在其他Atlassian产品上使用。
填补空缺 (Fill the Gap)
As a developer with a near 100% history in Open Source, I found the experience of dipping my toes into the World of enterprise development an unusual one. Documentation can be hard to find, there are fewer open community forums for discussing problems, and fewer open repositories of code examples. If you’re willing to commit to paid developer programs, then of course you get direct access to experts who are able to help you through problems (and I thank the Atlassian staff who helped me with mine).
作为一个在开放源代码领域拥有近100%历史的开发人员,我发现将自己的脚趾插入企业开发领域的经历是不寻常的。 文档可能很难找到,用于讨论问题的开放社区论坛越来越少,代码示例的开放存储库也越来越少。 如果您愿意致力于付费的开发人员计划,那么您当然可以直接与能够解决问题的专家联系(并感谢帮助我解决问题的Atlassian员工)。
I encourage you to investigate the potential for your ideas with the Atlassian Marketplace, with products that cover project management, communication, document management, version control, and continuous integration. I’m sure you can find a gap to fill somewhere.
我鼓励您使用Atlassian Marketplace(涵盖项目管理,通信,文档管理,版本控制和持续集成的产品)来研究您的想法的潜力。 我相信您可以在某个地方找到空白。
翻译自: https://www.sitepoint.com/developing-add-ons-for-enterprise-apps-like-jira/
jira 应用程序连接