Created
July 28, 2025 19:36
-
-
Save wjkennedy/c99b8568ee52b3120df444292714fc4a to your computer and use it in GitHub Desktop.
jenkinstojiraautomation POC
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import os | |
| import re | |
| import json | |
| def extract_jira_steps(jenkinsfile_content): | |
| """ | |
| Extracts usage of deprecated jira-steps from a Jenkinsfile. | |
| Returns a dict mapping step name to parameter dicts. | |
| """ | |
| jira_steps = ["jiraAddComment", "jiraTransitionIssue", "jiraNewIssue"] | |
| pattern = r'(jira\w+)\s*\(([^)]*)\)' | |
| matches = re.findall(pattern, jenkinsfile_content) | |
| extracted = [] | |
| for step, args in matches: | |
| if step in jira_steps: | |
| args_dict = {} | |
| for arg in args.split(','): | |
| kv = arg.strip().split(':', 1) | |
| if len(kv) == 2: | |
| key, value = kv[0].strip(), kv[1].strip() | |
| args_dict[key] = value.strip('"').strip("'") | |
| extracted.append({'step': step, 'args': args_dict}) | |
| return extracted | |
| def convert_to_jira_automation(step, args): | |
| """ | |
| Converts a deprecated step and args to Jira Automation JSON syntax. | |
| """ | |
| if step == "jiraAddComment": | |
| return { | |
| "trigger": "manual", | |
| "condition": {"type": "issue", "field": "key", "operator": "exists"}, | |
| "action": {"type": "comment", "comment": args.get("comment", "Jenkins build update.")} | |
| } | |
| elif step == "jiraTransitionIssue": | |
| return { | |
| "trigger": "manual", | |
| "condition": {"type": "issue", "field": "status", "operator": "not_equals", "value": args.get("transition", "")}, | |
| "action": {"type": "transition", "transition": args.get("transition", "Done")} | |
| } | |
| elif step == "jiraNewIssue": | |
| return { | |
| "trigger": "manual", | |
| "action": { | |
| "type": "createIssue", | |
| "project": args.get("projectKey", "PROJ"), | |
| "summary": args.get("summary", "Created by Jenkins"), | |
| "issueType": args.get("issueType", "Task") | |
| } | |
| } | |
| return {} | |
| def process_jenkinsfile(file_path): | |
| with open(file_path, 'r') as f: | |
| content = f.read() | |
| extracted_steps = extract_jira_steps(content) | |
| automation_rules = [] | |
| for step_info in extracted_steps: | |
| rule = convert_to_jira_automation(step_info['step'], step_info['args']) | |
| if rule: | |
| automation_rules.append(rule) | |
| return automation_rules | |
| # Example run | |
| jenkinsfile_path = "/mnt/data/sample_Jenkinsfile" # Replace with actual path | |
| automation_json = process_jenkinsfile(jenkinsfile_path) | |
| import pandas as pd | |
| import ace_tools as tools | |
| df = pd.DataFrame(automation_json) | |
| tools.display_dataframe_to_user(name="Jira Automation Rules", dataframe=df) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment