Working with JIRA from the command line

We normally interact with JIRA via the browser. Sometimes, it is useful to be able to use the command line, especially for administrative tasks or writing shell scripts.

In this recipe, we will use the command line to create new users in JIRA.

Getting ready

For this recipe, you need to have the Atlassian Command Line Interface (CLI) tool available on your workstation. You can download it from the following link:

How to do it...

To use the Atlassian CLI tool, we first need to enable the Remote API from JIRA:

  1. Navigate to Administration | System | General configuration.
  2. Click on the Edit Settings button.
  3. Turn on the Accept Remote API call settings.
  4. Click on Update to apply the change.

    You then need to install the Atlassian CLI tool by unzipping it to a convenient location on your workstation. Next, update the jira.sh (for UNIX) or jira.bat (for Windows) file to add in JIRA's details.

    For example, as shown in the following command, JIRA is running on http://localhost:8080 , and the administrator credential is admin_user with admin_password as the password:

            java -jar 'dirname $0'/lib/jira-cli-3.8.0.jar
            -server http://localhost:8080 --user admin_user
            --password admin_password "$@"
    
  5. So now that we have everything set up, we can run the following command to create a new user in JIRA:
            ./jira.sh --action addUser --userId tester 
            -userEmail [email protected] --userFullName
            Tester
    
  6. You should get a response as shown in the following code:
            User: tester added with password: 
            89u66p3mik5q.  Full name is: Tester.  Email is:
            [email protected].
    

How it works...

The Atlassian CLI tool works by accessing JIRA features via its Remote SOAP and REST API, which need to be enabled first.

We updated the JIRA script file with JIRA details, so we don't have to specify them every time; this is useful if we want to use the tool in a script. When we run the JIRA script, it will have all the necessary connection information.

The Atlassian CLI comes with a list of command actions such as the addUser action that we used to create users in JIRA. You can get a full list of actions from the following link:

https://bobswift.atlassian.net/wiki/display/JCLI/Documentation

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset