In this example, we will try to install in 5 minutes a PHP Jira Client script in a MacOS system. The prerequisites are:

Install instructions with example:

Download and Install PHP Composer.

curl -sS https://getcomposer.org/installer | php

Captura de pantalla 2019-10-05 a las 17.10.01

Next, run the Composer command to install the latest version of php jira rest client (and other dependencies like JsonMapper or Phpdotenv).

php composer.phar require lesstif/php-jira-rest-client
php composer.phar require netresearch/jsonmapper
php composer.phar require vlucas/phpdotenv

Captura de pantalla 2019-10-05 a las 17.10.54

Captura de pantalla 2019-10-05 a las 17.32.39

Captura de pantalla 2019-10-05 a las 17.33.27

Then run Composer’s install or update commands to complete installation.

php composer.phar install

Captura de pantalla 2019-10-05 a las 17.11.39

After installing, create in the same directory a hidden file called “.env”:

vim .env

With this content (remember to adapt the parameters to your Jira installation)


JIRA_HOST="https://your-jira.host.com"
JIRA_USER="jira-username"
JIRA_PASS="jira-password"
JIRA_LOG_ENABLED=true
JIRA_LOG_FILE="jira-rest-client.log"
JIRA_LOG_LEVEL="WARNING"

JIRA_REST_API_V3=false

After installing, create in the same directory a file called “GetProjectInfo.php”:

vim GetProjectInfo.php

with this content: (remember to add the usual php tags)

require 'vendor/autoload.php';

use JiraRestApi\Project\ProjectService;
use JiraRestApi\JiraException;

try {
    $proj = new ProjectService();

    $p = $proj->get('TEST');
	
    var_dump($p);			
} catch (JiraException $e) {
	print("Error Occured! " . $e->getMessage());
}

Captura de pantalla 2019-10-05 a las 18.09.31

As you can see, you need to require Composer’s autoloader in the file:

require 'vendor/autoload.php';

Now we are ready to run the script!:

php GetProjectInfo.php

Captura de pantalla 2019-10-05 a las 17.36.40

It’s very easy!

Here more info about the methods of the JIRA client PHP API

By MrAddon

Posted by:.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s