我想保存每晚构建的副本,我想将每个构建放入自己的日常文件夹中会是一个想法。但是我无法使用构建机器人主站的时间.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"]))
如何获取当前运行日期以在目标中使用?
更好的方法是使用自定义渲染器进行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)))
您需要在构建配置中将日期设置为运行时的属性。做这样的事情:
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"]))
确保将插值和设置属性从命令导入到:
from buildbot.process.properties import Interpolate
from buildbot.steps.shell import SetPropertyFromCommand