I'm configuring an Android application build process with Jenkins pipeline.
At the beginning and the end of the build, a message is sent to a Slack channel. The relevant portion of the Jenkinsfile looks like so:
slackSend (channel: '#slack-test', color: 'warning', message: "Finished: Job '${env.JOB_NAME} [${env.BUILD_NUMBER}]' State: ${STATE}. Artifacts can be viewed here: ${env.BUILD_URL}artifact/Product/build/outputs/ ")
I'd also like the Slack notification to include the time it took for the build to run. Is it possible to do this without adding any external plugins?
If there's an environment variable which holds this information it would be perfect, but I can't find such a variable.
You can use ${currentBuild.durationString}
to get build duration. I'm using it in my declarative pipeline scripts.
Note: If you're using HipChat plugin, you can use ${BUILD_DURATION}
(previously ${DURATION}
) variable in your hipchatSend
command (it is propagated by the plugin with some other variables).
Example:
post {
success {
hipchatSend color: 'GREEN', room: 'My room', failOnError: true, notify: false,
message: 'Build <a href=\'${BUILD_URL}\'>${JOB_DISPLAY_NAME} #${BUILD_NUMBER}</a> has been built. Took ${BUILD_DURATION}. See the <a href=\'${BUILD_URL}/console\'>output</a>.'
}
}
Here is some more info on Jenkins environment variables that can be used in job configuration.
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