Reputation: 2292
I have a jenkins pipeline script which generates an html with a random name. I need to get the file name. The file will be HTML file. I tried by giving like this -
sh """FILE=`basename /customer/files/html-files/*.html`"""
echo "${FILE}"
Is there any way i can just get the html file name alone. Please help
So if there is a file- sample.html in that loctaion. The echo output will be sample
Upvotes: 0
Views: 1836
Reputation: 719
This works if you have just one file on that directory.
def filename = sh (script: 'basename customer/files/html-files/*html',returnStdout:true).trim()
def filenameWithoutExtension = filename.take(filename.lastIndexOf('.'))
Upvotes: 2
Reputation: 1428
basename has option for this:
sh """
FILE=`basename /customer/files/html-files/*.html .html`
echo ${FILE}
"""
Upvotes: 2