Sign in
agent:

Trigger this job with the parameter value set to the new branch name

There was a problem that the LLM was not able to address. Please rephrase your prompt and try again.

This code triggers the specified Jenkins job with the given parameter value using the Jenkins API.

import json import requests from requests.auth import HTTPBasicAuth branch_name = new_branch_name # Get environment variables JENKINS_USERNAME = getEnvVar('JENKINS_USERNAME') JENKINS_API_TOKEN = getEnvVar('JENKINS_API_TOKEN') JENKINS_URL = getEnvVar('JENKINS_URL') # Print input parameters print(f"Input Parameters:\njob_name: {job_name}\nbranch_name: {branch_name}") # Jenkins API URL to trigger the job with parameters url = f"{JENKINS_URL}/job/{job_name}/buildWithParameters" # Headers for authentication headers = { 'Content-Type': 'application/json', 'Accept': 'application/json' } # Parameters to trigger the job params = { 'Branch': branch_name } # Make the request to Jenkins API to trigger the job response = requests.post(url, headers=headers, auth=HTTPBasicAuth(JENKINS_USERNAME, JENKINS_API_TOKEN), params=params) if response.status_code == 201: print(f"Output:\nJob triggered successfully.") else: print(f"Failed to trigger job. Status code: {response.status_code}")
copied