问题
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?
回答1:
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
回答2:
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)))
来源:https://stackoverflow.com/questions/35793722/how-to-a-create-a-daily-build-folder-using-buildbot