Developing JIRA Plugins Using Nodejs

jira-nodejs

Installation:

1. Check whether have you installed Java 8, if not install.

for Ubuntu users

$ sudo add-apt-repository ppa:webupd8team/java
$ sudo apt-get update
$ sudo apt-get install oracle-java8-installer

2. Now install Atlassian SDK from here.

3. We need to install nodejs for plugin to work, install node from here for ubuntu developers.

4. Install ACE - Atlassian Connect Express using the npm install command.

$ npm install -g atlas-connect

Note: for more about Atlassian Connect Express click here.

5. Create a new ACE project called jira-example.

$ atlas-connect new jira-example
  1. Change to your new jira-example directory and run 3 simple command
$ cd jira-example
$ npm install
$ atlas-run-standalone --container tomcat7x --product jira --version 7.1.0-OD-01-053 --data-version 7.1.0-OD-01-053 --bundled-plugins com.atlassian.bundles:json-schema-validator-atlassian-bundle:1.0.4,com.atlassian.upm:atlassian-universal-plugin-manager-plugin:2.20.1-D20150924T170115,com.atlassian.jwt:jwt-plugin:1.5.4,com.atlassian.plugins:atlassian-connect-plugin:1.1.61 --jvmargs -Datlassian.upm.on.demand=true

7. In a browser window, navigate to your JIRA instance. JIRA should be at http://localhost:2990/jira.

8. Log in with the following credentials.

Username: admin
    Password: admin

You might see a message that JIRA's base URL doesn't match your local host. You can click to update JIRA's base URL, or hide the message.

9. Open a new terminal window, From your jira-example root, start up a Node.js server.

$ node app.js

Development:

Open your project in your favourite Text Editor or IDE.

1. Locate atlassian-connect.json, this file is responsible for installing your plugin with jira, Replace the key, name, description, and vendor name and URL with your desired values.

2. There is key called modules in atlassian-connect.json, this is reponsible for adding modules in plugin and diplaying them on the webpage. For more check this link.

"key": "jira-example",
"name": "JIRA Example Project",
"description": "A Connect add-on that displays clock in jira issue page",
"vendor": {
    "name": "Jane Doe",
    "url": "https://developer.atlassian.com/"
},
"modules": {
    "webPanels": [{
        "key": "sys-clock",
        "location": "atl.jira.view.issue.right.context",
        "name": {
            "value": "System clock"
        },
        "url": "/sys_clock",
        "conditions": [{
            "condition": "user_is_logged_in"
        }]
    }]
}

3. Navigate to routes directory and open file index.js, add this code.

app.get('/sys_clock', addon.authenticate(), function(req, res) {
     res.render('sys_clock', { title: "JIRA Example" });
});

4. Navigate to views directory and create file sys_clock.hbs, add this code.

<div id="sys_clock"></div>

5. Navigate to public/js directory and add this code to addon.js.

var sysClock = {
    today: new Date(),
    h: 0,
    m: 0,
    s: 0,
    init: function init () {
        this.d = this.today.getDate();
        this.dd = this.getDay();
        this.mm = this.getMonth();
        this.y = this.today.getFullYear();
        this.startTime();
    },
    getDay: function getDay () {
        var day = ['Sun', 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat'];
        return day[this.today.getDay()]
    },
    getMonth: function getMonth () {
        var month = ['January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December'];
        return month[this.today.getMonth()]
    },
    startTime: function startTime () {
        var today = new Date();
        this.h = today.getHours();
        this.m = this.checkTime(today.getMinutes());
        this.s = this.checkTime(today.getSeconds());
        document.getElementById('sys_clock').innerHTML =
        this.mm + ' ' + this.dd + ' ' + this.d + ' - ' + this.y + ' ' + this.h + ':' + this.m + ':' + this.s;
        var t = setTimeout(function () {
            this.startTime();
        }.bind(this), 500);
    },
    checkTime: function checkTime (i) {
        if (i < 10) {i = '0' + i}; // add zero in front of numbers < 10
        return i;
    }
};

Deployment:

The plugin is deployed locally or in cloud, but first we will see how it will be deployed locally.

Locally:

1. To Deploy plugin we need admin right, in test environment we are given admin right.

So, click the cog icon on top right side of you screen.

Dropdown > issues > manage issues > upload addon

2. Paste the url of node application running locally on you device.

http://localhost:3000/atlassian-connect.json

3. The plugin will be installed, now open any issue page.

Cloud:

The complete deployment of plugin in cloud is well documented here.

There are lot of thing we can do with the power of web in jira.

Source: Atlassian Developer

Tags: