agent: |
K08j2kQDt6VIlhlXH5EMGet the console output of last Jenkins job build
Get the console output of last Jenkins job build
There was a problem that the LLM was not able to address. Please rephrase your prompt and try again.
Python script to get the console output of the last build for the Jenkins pipeline 'taskservice'
inputs
outputs
import requests
import time
# Get environment variables
jenkins_username = getEnvVar('JENKINS_USERNAME')
jenkins_api_token = getEnvVar('JENKINS_API_TOKEN')
jenkins_url = getEnvVar('JENKINS_URL')
# Jenkins API endpoint to get the console output
url = f'{jenkins_url}/job/{pipeline_name}/lastBuild/logText/progressiveText?start=0'
# Function to get the console output
def get_console_output(url, auth):
response = requests.get(url, auth=auth)
if response.status_code == 200:
return response.text
else:
return f'Failed to fetch console output: {response.status_code}'
# Get the console output
console_output = get_console_output(url, (jenkins_username, jenkins_api_token))
# Print inputs and outputs
print('Pipeline Name:', pipeline_name)
print('Console Output:', console_output)
# Output the console output
console_output
copied