Phil Hannent
Phil Hannent

Reputation: 12317

How to a create a daily build folder using buildbot?

I want to save a copy of the nightly build, I figured putting each build into its own daily folder would be idea. However I cannot use the time from buildbot master.cfg because that it set when it is configured:

copy_files = [".\\release\\MyProgram.exe",
              ".\\install\\ChangeLog.js",
              ".\\translations.txt"]
server_dest_path_by_date = server_dest_path + "\\{0}".format(time.strftime("%Y-%m-%d"))
my_return.addStep(steps.MakeDirectory(dir=server_dest_path_by_date))
for file in copy_files:
    my_return.addStep(ShellCommand(command=["copy", file, server_dest_path_by_date, "/y"]))

How would I get the current run date for use in the destination?

Upvotes: 4

Views: 459

Answers (2)

Sergei Nikulov
Sergei Nikulov

Reputation: 5110

The better way is to use a custom renderer for util.Interpolate(...)

@util.renderer
def cur_date(props):
    return datetime.date.today().isoformat()

And later use it as custom keyword in build factory step

cppcheck_dst = '/home/upload/%(kw:cur_date)s/'
bF.addStep(steps.MakeDirectory(dir=util.Interpolate(cppcheck_dst, cur_date=cur_date)))
bF.addStep(steps.CopyDirectory(src='build/build.scan/static/',
                               dest=util.Interpolate(cppcheck_dst, cur_date=cur_date)))

Upvotes: 2

Haris Khaliq
Haris Khaliq

Reputation: 11

You need to set the date as a Property during runtime in your build config. Do something like this:

my_return.addStep(SetPropertyFromCommand(
    property = 'dateRightNow', 
    command = ['python', '-c', '"import datetime;print  datetime.datetime.now().strftime('%y-%m-%d')"']
    ))

For Python 3.6:

my_return.addStep(SetPropertyFromCommand(
    property = 'dateRightNow', 
    command = ['python', '-c', 'import datetime;print(datetime.datetime.now().strftime("%y-%m-%d"))']
    ))

and then use the property like this:

my_return.addStep(steps.MakeDirectory(
    dir=Interpolate('%(prop:dateRightNow)s')))
for file in copy_files:
    my_return.addStep(ShellCommand(command=["copy", file, Interpolate('%(prop:dateRightNow)s'), "/y"]))

Make sure you import Interpolate and setPropertyFromCommand unto:

from buildbot.process.properties import Interpolate
from buildbot.steps.shell import SetPropertyFromCommand

Upvotes: 1

Related Questions