I thought for a bit of a laugh I would challenge myself to create an ABX action to raise a Jira ticket when a deployment fails. In the end it wasn’t too difficult and it certainly shows that there could be some good further use cases for integration between Jira and vRA8.

So, what do we have?

  1. A Windows 2019 server running Atlassians Jira system (on-premise)
  2. A Jira project – we need to know the project key
  3. Details of a Jira account (username and password) that have permissions to create and modify Jira tickets
  4. Some Python code in an ABX (note my vRA has internet access, if yours doesn’t, you will need to download and package the required library and upload to vRA)
  5. You may need to change the issue type depending on your project setup – mine is simply ‘Bug’

Create a Python action and copy the code in.

def handler(context, inputs):

from atlassian import Jira
import json

jira = Jira(
url=context.getSecret(inputs["jiraUrl"]),
username=context.getSecret(inputs["jiraUsername"]),
password=context.getSecret(inputs["jiraPassword"]))

result = jira.issue_create(fields={
'project': {'key': 'IT'},
'issuetype': {
"name": "Bug"
},
'summary': 'Deployment ' + inputs["__metadata"]["eventType"] + ' ' + inputs["status"],
'description': 'Deployment in project ' + inputs["projectName"] +
' for user ' + inputs["userName"] +
' failed with error ' + inputs["failureMessage"] + 
' ------> ' + 
json.dumps(inputs, indent=2),
})

The Setup

Action Constants

I have created 3 action constants; one for the Jira URL, one for a Jira user account and finally an encrypted one for the Jira account password.

Action Setup

The action requires the Action Constants to be added as inputs. Add a new input for each. There is a dependency on the atlassian-python-api library, that needs to be stated to.

Event Subscriptions

I set up the action to be triggered on one event subscriptions, Deployment completed. Note that I have used a Condition filter to ensure that the action is only triggered when a deployment fails.

And, when a deployment does fail, I now get a Jira ticket raised!

paul_davey

CIO at Sonar, Automation Practice Lead at Xtravirt and guitarist in The Waders. Loves IT, automation, programming, music

%d bloggers like this: