【问题标题】:Buildbot: how to skip a step if a file doesn't exist?Buildbot:如果文件不存在,如何跳过一个步骤?
【发布时间】:2015-02-13 10:41:52
【问题描述】:

在构建一些分支时,我需要跳过构建步骤。

更准确地说,我只想在要运行的脚本存在于源代码树上时执行ShellCommand 步骤。

我试过了:

ShellCommand(command=["myscript"],
             workdir="path/to",
             doStepIf=(lambda step: os.path.isfile("path/to/myscript")))

但该步骤从未执行。

【问题讨论】:

    标签: buildbot


    【解决方案1】:
    def doesMyCriticalFileExist(step):
       if step.getProperty("myCriticalFileExists"):
          return True
       return False
    
    <factory>.addStep(SetProperty(command='[ -f /path/to/myscript ] && ls -1 /path/to/myscript || exit 0', property='myCriticalFileExists')))
    <factory>.addStep(ShellCommand(command=["myscript"], workdir="path/to", doStepIf=doesMyCriticalFileExist))
    

    【讨论】:

      【解决方案2】:

      最好的做法是在上一步中设置一个属性,然后在 doStepif 方法中检查该属性。您在那里的 os.path.is 文件在配置时运行,(buildbot 启动)而不是运行时。

      【讨论】:

      • 您能否详细说明如何设置和使用属性?
      【解决方案3】:

      我最终通过让步骤无条件运行但设置haltOnFailure=False 解决了这个问题。这样,如果所需的文件不存在,它会失败但不会终止构建的其余部分。

      【讨论】:

        【解决方案4】:

        在步骤之前使用简单的python if 语句:

        if(condition):
          your buildbot step
        

        【讨论】:

        • 这不是 buildbot 的工作方式。不能像这样有条件地添加步骤,因为在主脚本的“运行”中,该目录可能不存在。步骤本身必须具有跳过 doStepIf 的逻辑。 documentation 甚至提到有条件不能按预期工作。
        猜你喜欢
        • 2021-12-27
        • 1970-01-01
        • 2013-07-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2018-06-12
        • 2018-02-08
        • 1970-01-01
        相关资源
        最近更新 更多