我想保存每晚构建的副本,我想将每个构建放入其自己的每日文件夹中是有意义的。但是我无法使用buildbot master.cfg中的时间,因为它在配置时设置:
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"]))
我如何获得目的地的当前运行日期?
您需要在构建配置中的运行时期间将日期设置为属性。做这样的事情:
my_return.addStep(SetPropertyFromCommand(
property = 'dateRightNow',
command = ['python', '-c', '"import datetime;print datetime.datetime.now().strftime('%y-%m-%d')"']
))
对于Python 3.6:
my_return.addStep(SetPropertyFromCommand(
property = 'dateRightNow',
command = ['python', '-c', 'import datetime;print(datetime.datetime.now().strftime("%y-%m-%d"))']
))
然后使用这样的属性:
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"]))
确保导入Interpolate和setPropertyFromCommand至:
from buildbot.process.properties import Interpolate
from buildbot.steps.shell import SetPropertyFromCommand
更好的方法是为util.Interpolate(...)
使用自定义渲染器
@util.renderer
def cur_date(props):
return datetime.date.today().isoformat()
然后在构建工厂步骤中将其用作自定义关键字
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)))