Automating UPM using API's - PART 1

Have you ever wondered if there is an easier way to automate the installation and licensing of apps from the Marketplace? Especially if you're behind a firewall and your Atlassian stack doesn't have internet access!

Thanks to several API's and a few hours of playing around, I've pieced together various python scripts that can automate:

  • Downloading .jar and .obr files from Marketplace
  • Upload to a local repository like Artifactory
  • Install into UPM using the above Artifactory URL
  • License using either a local file

Getting set up

Firstly, you'll need python3 - I recommend downloading from https://www.python.org/downloads/

Next, create a folder to work in. Inside that folder create a requirements.txt file with the following

colorama==0.4.1
PyYAML==5.1
requests==2.22.0
urllib3==1.25.3
artifactory==0.1.17

Note: not all of these are required, just depends on what you use in the end.

Once you have python installed, I recommend using a virtualenv - Open up your favourite terminal and change into your working folder

  1. Install virtualenv with pip:
pip install virtualenv
  1. create a new virtual env
virtualenv venv -p python3
  1. Activate your virtual env
source venv/bin/activate
  1. Install the dependencies
pip install -r requirements.txt

 

Create a new YAML (.yml) file my-atlassian-apps.yml with the following in it:

atlassian:
  artifactory_url: https://artifactory.example.com/artifactory
  atl_marketplace_cdn: https://marketplace-cdn.atlassian.com/files
  atl_marketplace_url: https://marketplace.atlassian.com
  environments:
    - name: prod
      stacks:
        - app_stack: primary
          confluence:
            app_url: https://confluence.example.com
            applications:
              confluence:
                version: 6.13.8
            apps:
              ch.bitvoodoo.confluence.plugins.navitabs:
                version: 4.6.0
              ch.bitvoodoo.confluence.plugins.registration:
                version: 1.3.0
           jira:
             app_url: https://jira.example.com
             applications:
               jira-servicedesk:
                 version: 4.5.4
               jira-software:
                 version: 8.5.4
             apps:
               co.uk.jackgraves.jira-optimiser:
                 version: 4.0.14-jira8-DC
               com.addteq.jira.plugin.accessibility.addteq-jira-unstoppable:
                 version: 1.5.10
               com.akelesconsulting.jira.plugins.MultipleChartsGadget:
                 version: 2.4.2

Note: You can replace values above with your relevant values including the apps ID with ones that you want to be installed. You can get these from an existing installation of the app

Create a new python (.py) file atlassian-apps.py with the following in it:

#!/usr/local/bin/python
import argparse
import base64
import boto3
import getpass
import json
import os
import requests
import pathlib
import signal
import ssl
import subprocess
import sys
import urllib3
import yaml
from artifactory import ArtifactoryPath
from botocore.exceptions import ClientError
from colorama import Fore, Style, init
from pkg_resources import parse_version

urllib3.disable_warnings()

init(autoreset=True)

def sigint_handler(signal, frame):
    print(f"{Style.DIM}You pressed Ctrl+C!")
    sys.exit(1)

signal.signal(signal.SIGINT, sigint_handler)

parser = argparse.ArgumentParser()
parser.add_argument(
    '-e', '--environment',
    required=True,
    choices=['prod', 'nonp'],
    help="Please select an environment"
    )
parser.add_argument(
    '-s', '--stack',
    required=True,
    choices=['primary', 'secondary'],
    help="Please select a stack"
    )
parser.add_argument(
    '-a', '--application',
    required=True,
    choices=['jira', 'confluence'], # you can also add , 'bitbucket', 'bamboo', just be sure to add them to your yml file too
    help="Please select an application"
    )
parser.add_argument(
    '--username',
    help="Please provide a username"
    )
parser.add_argument(
    '--download',
    action='store_true',
    help="Download this application/app?"]
    )
parser.add_argument(
    '--upload',
    action='store_true',
    help="Upload this application/app?"
    )
parser.add_argument(
    '--install',
    action='store_true',
    help="Install this application/app?"
    )
parser.add_argument(
    '--license',
    action='store_true',
    help="License this application/app?"
    )

args = parser.parse_args()

# Get base64 credential
if not args.download:
    if args.username:
        username = password = args.username
    else:
        username = input("\nUsername: ")
        password = getpass.getpass()
base64string = '%s:%s' % (username, password)
b64auth = base64.b64encode(bytes(base64string, 'utf-8'))
b64authtoken = b64auth.decode('utf-8')

Now you're ready to start adding to it!

Check out part 2

2 comments

JiraJared
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
May 1, 2020
Taranjeet Singh
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
May 19, 2020

@JiraJared Very helpful automation for add-ons installation!

Comment

Log in or Sign up to comment
TAGS
AUG Leaders

Atlassian Community Events