mn0MOf19DMzQZqaaSJ4gTrigger a Jenkins job with param values
Trigger a Jenkins job with param values
There was a problem that the LLM was not able to address. Please rephrase your prompt and try again.
Python script to trigger the Jenkins pipeline 'taskservice' with the default parameter value
inputs
outputs
import requests
# Get environment variables
jenkins_username = getEnvVar('JENKINS_USERNAME')
jenkins_api_token = getEnvVar('JENKINS_API_TOKEN')
jenkins_url = getEnvVar('JENKINS_URL')
# Jenkins API endpoint to trigger the pipeline with parameters
# pipeline_name = 'taskservice'
url = f'{jenkins_url}/job/{pipeline_name}/buildWithParameters'
# Default parameter value
# params = {'Branch': 'main'}
# Make the request to trigger the pipeline
response = requests.post(url, auth=(jenkins_username, jenkins_api_token), params=params)
# Check if the request was successful
if response.status_code == 201:
trigger_status = 'Pipeline triggered successfully'
else:
trigger_status = f'Failed to trigger pipeline: {response.status_code} - {response.text}'
# Print inputs and outputs
print('Pipeline Name:', pipeline_name)
print('Parameters:', params)
print('Trigger Status:', trigger_status)
copied