See this in action in our Sanbox https://radbee-sandbox.atlassian.net
Skip to end of metadata
Go to start of metadata

You are viewing an old version of this page. View the current version.

Compare with Current View Page History

« Previous Version 3 Next »

We are showing here an example of how the Jira Snapshots API can be called from using Python codes that is triggered from a GitHub Action.
Similar implementations can be done in any language, so this example is given for the sake of demonstration.
Prerequisites:

  1. A Jira Snapshot exists, and it has each API enabled as explained on this page.

  2. The Api Key is known, and set by an environment variable (in the code snippet, “SNAPSHOT_APIKEY”)

  3. The web request endpoint is available through the environment variable (in the code snippet, “SNAPSHOTS_WEB_REQUEST_URL”)

A snippet of the GitHub Workflow file:

name: RadBee-Sandbox Test

on: 
  workflow_dispatch:
    inputs:
      snapshots_web_request_url:
        description: 'Snapshots web request url'
        required: true
        type: string
      snapshots_apikey:
        description: 'Snapshots api key'
        required: true
        type: string

permissions:
    contents: read

env:
  PYTHON_VERSION: '3.11'
  SNAPSHOTS_WEB_REQUEST_URL: ${{ inputs.snapshots_web_request_url }}
  SNAPSHOTS_APIKEY: ${{ inputs.snapshots_apikey }}

jobs:
  build:
      runs-on: macos-latest
      steps:
      - uses: actions/checkout@v3
      - name: Set up Python ${{ env.PYTHON_VERSION }}
        uses: actions/setup-python@v4
        with:
          python-version: ${{ env.PYTHON_VERSION }}
      - name: Install dependencies
        run: |
          python -m pip install --upgrade pip
          python tests/take_snapshot.py

And this is the snippet of the Python program:

import requests
import os


def take_snapshot():
    print("Start taking snapshot...")
    url = os.environ["SNAPSHOTS_WEB_REQUEST_URL"]
    headers = {"jira-snapshots-api-key": os.environ["SNAPSHOTS_APIKEY"]}
    response = requests.post(url, headers=headers)
    if response.status_code == 200:
        print("Snapshot was triggered successfully!")
    else:
        print(f"Error on taking snapshot: {response.status_code}")


# run
if __name__ == "__main__":
    take_snapshot()
  • No labels