How do I access $BUILD_LOG
in a Jenkins pipeline, or is there a better way of getting the log output?
Going off of this answer, I've been trying to access the $BUILD_LOG
environment variable, but when I try
echo "${BUILD_LOG, maxLines=50, escapeHtml=false}"
the build errors out:
org.codehaus.groovy.control.MultipleCompilationErrorsException: startup failed:
WorkflowScript: 11: unexpected token: BUILD_LOG @ line 11, column 29.
echo "${BUILD_LOG, maxLines=50, escapeHtml=false}"
And if I try
echo "$BUILD_LOG"
I get this error:
groovy.lang.MissingPropertyException: No such property: BUILD_LOG for class: groovy.lang.Binding
What am I doing wrong? Or is this the wrong way to access the printed output?
On this page, click Build Now on the left to run the Pipeline. Under Build History on the left, click #1 to access the details for this particular Pipeline run. Click Console Output to see the full output from the Pipeline run. The following output shows a successful run of your Pipeline.
In order to use the timestamp information from Jenkins, you need to install the Build Timestamp Plugin and set the timestamp format in the Jenkins configuration (for example, to "yyyyMMdd-HHmm"). In every place where we use the Docker image, we need to add the tag suffix: ${BUILD_TIMESTAMP} .
Step 4) Go to your Jenkins dashboard and create a view by clicking on the “+” button. Select the Build Pipeline View option and click OK. Step 5) Under Pipeline view configuration, locate Pipeline Flow. Under Pipeline flow, select the initial job to run.
I had the same problem with declarative pipelines and a step like:
emailext(
subject: "foo",
to: "bar",
body: """<p>FAILED: Job '${env.JOB_NAME} [${env.BUILD_NUMBER}]':</p>
<p>Console output (last 250 lines):<hr><pre>${BUILD_LOG}</pre></p>"""
I had email ext plugin installed.
The solution was to escape the $-sign of the the macro that should be expanded by the plugin, like so:
...
<p>Console output (last 250 lines):<hr><pre>\${BUILD_LOG}</pre></p>"""
...
And be sure to use double quotes.
This way groovy (?) will first expand all the environment variables, and leaves the escaped variables to be dealt with by email ext plugin.
Still haven't found a solution to use BUILD_LOG parameter in a pipeline job with emailext plugin.
As a small solace, I found a workaround to access build log in another way:
currentBuild.rawBuild.getLog(15)
Where 15 is a number of last log lines I want to show.
The example is:
emailext attachLog: true,
body: "Build failed" +
"<br> See attached log or URL:<br>${env.BUILD_URL}" +
"<br><br> <b>The end of build log is:</b> <br>" +
currentBuild.rawBuild.getLog(15).join("<br>"),
mimeType: 'text/html',
subject: "Build failed",
to: '[email protected]'
Note that you have to approve a few script signatures at the In-Process Script Approval in order to allow usage of this function.
From the answer you linked the BUILD_LOG variable is set by the email-extension plugin. Do you have this configured correctly as this may be your issue.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With