JIRA探究——anti-XSRF报错下插件的直接安装与升级

1,027 阅读3分钟

前言

在JIRA部署和安装的过程中,我们往往会遇到不少报错。但是有一个报错往往是我们在已经部署完整个JIRA套件的架构之后才被我们发现。这个故障就是常见的Invalid anti-XSRF token provided. The valid token should be retrieved transparently, but you may want to perform a hard refresh in your browser and try again before creating a support issue.报错。报错截图如下:

这个报错的发生原因往往是我们根据实际需求,在JIRA服务器或者外部配置了HTTP转发、解析导致。但是在实际使用过程中,由于我们已经设计好了部署架构,这个时候进行代理和转发的重新设计部署,往往会带来巨大的运维成本。所以此时推荐使用JIRA原生支持的jar包直接安装方法。

方法

在Atlassian JIRA的官方文档里面,我们可以轻松的查到关于这个报错的说明:Unable to install or update Add-ons via UPM due to Invalid anti-XSRF token provided

但是在这个页面中,对于解决方法的说明其实模棱两可,即便使用所说的UMP工具进行安装,报错依然存在。这个时候,通过查阅JIRA的用户手册,我们可以找到JIRA对于jar包直接安装、升级plugin的说明:

#A few considerations apply to installing or uninstalling add-ons created with the SDK version 1 framework. These types of add-ons are identified #in their Marketplace listing as 'Plugins 1' add-ons.
#
#You cannot install Plugins 1 add-ons into JIRA or Bamboo using the Universal Plugin Manager. You must download the add-on distribution and follow #its specific installation instructions. Such add-ons have a Download button rather than an Install button in their listing. In most cases you #will need to move or download the file to the <INSTALL_DIR>/atlassian-jira/WEB-INF/lib directory.
#Similarly, Plugins 1 JIRA and Bamboo add-ons do not have an Uninstall button. You must remove the add-on from the file system manually.
#In Confluence, you can install and uninstall Plugins 1 add-ons using the Universal Plugin Manager. You should see an Install or an Uninstall #button with the add-on entry.
#Once you have downloaded or created your add-on JAR file, follow these steps to install it to JIRA:

1. Shut down JIRA.
2. Copy your JAR file (e.g., example_plugin.jar) into the directory:
    2-1. If you are installing a Plugins 1 add-on, copy the JAR file into your JIRA installation directory under atlassian-jira/WEB-INF/lib/.
    2-2. If you are installing a Plugins 2 (OSGi) add-on, copy the JAR file into your JIRA home directory under plugins/installed-plugins/.
3. Start JIRA.
4. Confirm the installation by going to Administration > Manage Add-ons. Your add-on (e.g., example_plugin) should appear in the list as enabled.

我们可以看到,JIRA或者Bamboo的plugin分为两类,Plugin1和Plugin2(OSGi)。通俗点来讲,我们常用的java-mysql-connector这类连接器或者核心功能类的jar包,一般都是Plugin1类别的,通常放置在jira安装目录的atlassian-jira/WEB-INF/lib/下面。而从商店下载来的绝大多数第三方或者官方功能性plugin,都属于Plugin2(OSGi)类别的。其中Plugin2的jar包都被放置在jira家目录的plugins/installed-plugins目录下,如图所示:

所以假设我们有一个第三方的插件需要更新,则更新方法如下:

  1. 前往[JIRA官方商店](https://marketplace.atlassian.com/),查找需要安装的app并且在说明界面里点击Download下载安装包
  2. 停止jira服务或者关闭jira容器
  3. 把需要安装或者升级的plugin的jar包复制到jira主机的jira-home下的plugins/installed-plugins/。
  4. 启动jira服务或者容器。
  5. 进入jira的管理界面确认安全状态是否无误。

TIPs

需要注意的是有相当比例的apps安装包,是OBR格式的,这个时候我们只需要把这些安装包的后缀改为*.zip,解压后把文件夹和子文件夹里所有的*.jar文件按照上一节复制过去就可以了。