import requests from requests.auth import HTTPBasicAuth # Jenkins configuration jenkins_url = "https://scheduler.theorchard.io/" username = "" api_token = "" # You an generate token under your user profile in Jenkins # GitHub repository URL to search for github_repo_url = "https://github.com/theorchard/distro-scripts" # Get all jobs from Jenkins response = requests.get(f"{jenkins_url}/api/json?tree=jobs[name,url]", auth=HTTPBasicAuth(username, api_token)) jobs = response.json().get("jobs", []) # Function to check if a job uses the specified GitHub repository def job_uses_github_repo(job_url, repo_url): job_config_url = f"{job_url}config.xml" job_config_response = requests.get(job_config_url, auth=HTTPBasicAuth(username, api_token)) if job_config_response.status_code == 200: return repo_url in job_config_response.text return False # List jobs using the specified GitHub repository jobs_using_repo = [job["name"] for job in jobs if job_uses_github_repo(job["url"], github_repo_url)] # Print the jobs print("Jobs using the specified GitHub repository:") for job in jobs_using_repo: print(job)