Ashwin96
Ashwin96

Reputation: 31

How to create a folder with a timestamp and build id as the folder name and copy some files into that folder?

I need to take backup of a few artifacts (.dll files in this case) in a new folder called backup. I want a backup to be taken every time a build happens. I need Jenkins to create a folder with the time stamp and build number as the folder name and then copy the artifacts into that folder.

Upvotes: 2

Views: 1739

Answers (2)

uncletall
uncletall

Reputation: 6842

The simplest solution is to use the java date:

def now = new Date()
def filename = now.format("backup-$BUILD_NUMBER-yyyyMMddHHmm")

This will give you a filename of backup-123-201903291430

Upvotes: 2

VonC
VonC

Reputation: 1324278

All you need to do is add a build step creating that folder, as in this answer (which assumes a Windows agent)

But to have a portable way use/compute/use a timestamp, you can install the JENKINS ZenTimestamp Plugin, which means you will be able to use the BUILD_TIMESTAMP environment variable, and use if for your backup folder name.

The build number is part of the Jenkins Set Environment Variables: BUILD_NUMBER.

Upvotes: 1

Related Questions