AWS CodeCommit and JIRA integration

AWS CodeCommit service is the SCM tool, fully managed by AWS. You can make use of your existing git commands to work with repositories hosted on CodeCommit. AWS does not have any out-of-box integration for AWS CodeCommit and JIRA integrations by default. We can make use of AWS Lambda to create the integration between these two.

When we update the code on CodeCommit, we also need to track the commits corresponding to the issue. To make this happen, some of the tools provide out-of-the-box integrations to push the update to the SCRUM tools whenever a commit takes place.

I was working on AWS CodeCommit as SCM and JIRA for project management and for the tools that help me to push the commit message to the corresponding issue on JIRA. Most the of tools I have seen were paid tools and AWS CodeCommit not providing the out-of-the-box integration.

As I know that we can make use of the JIRA APIs to push/pull the details of the issue from the JIRA Cloud instance. So, we thought of writing a piece of Lambda code for AWS CodeCommit and JIRA integration using AWS CodeCommit, JIRA ReST APIs, AWS Lambda, and CLoudWatch.

The following is the step by step process:
  1. The user commits the changes to CodeCommit
  2. The CodeCommit event triggers the Lambda function to call the JIRA API for the issue
  3. Lambda function calls the JIRA API for the issue and updates the commit message
  • Create a Lambda function with python as the runtime. Attach the required IAM roles to access the AWS CodeCommit.
  • Create a Trigger and choose CodeCommit as the source. You can pick the particular branch and brach events if required. Whenever any commit made to the brach you configure, then the corresponding event triggers the Lambda function.

I have written a Python script to call the JIRA ReST APIs for the issue that we want to update. By Default, AWS Lambda does not support the requests module. So, you need to upload your code as a zip file along with all the dependencies such as requests. Please follow this article for the process to upload the custom package with dependencies.

The below code, get the commit message and repo name from the triggered event

  codeCommitObj = event['Records'][0]['codecommit']
  print(codeCommitObj)
  commitId = codeCommitObj['references'][0]['commit']
  repoARN = event['Records'][0]['eventSourceARN']
  repoName = repoARN.split(':')[-1]
  data = codecommit.get_commit(
        repositoryName = repoName,
        commitId = commitId,
  )

Once you get the required details from repo, you can now call the JIRA ReST api for the corresponding issue as below. You can get all other details such as author name, email etc. from the above.

    jiraUrl = "https://cloudtechiee.atlassian.net/rest/api/2/issue/"+issue_id+"/comment"
    jiraUserName = ""
    jiraPassword = ""
    jira_header = {'Content-Type': 'application/json'}
    post_data = {
        "body": str(issue_message)
    }
    res = requests.request('POST',jiraUrl,verify = false, auth=HTTPBasicAuth(jiraUserName, jiraPassword), data=post_data, headers=jira_header)

Now, you should be able to see the message in the comment section of the JIRA issue corresponding to the commit that made.

Hope, you find the article helpful to you.

Share your love

Newsletter Updates

Enter your email address below and subscribe to our newsletter

Leave a Reply

Your email address will not be published. Required fields are marked *