python - 奇怪的 buildbot python 行为

标签 python buildbot

编辑一些解释:buildbot 是 python 中的持续集成系统,可以通过 Web 界面进行控制。在此 Web 界面中,您有一个“瀑布”页面,您可以在其中选择特定的构建器并使用“强制构建”按钮触发构建。

网址:http://trac.buildbot.net/

背景:我们有一组连续的构建器(每隔几分钟检查一次是否发生更改,如果发生则重建)或每晚(每晚构建)。到目前为止,我们的系统只有一个针对每个项目的特定企业构建器。这是通过强制每个项目必须在一个常量 URL 下找到来完成的,例如

https://myrepositioryurl/{$projectname}.

然后,当一个项目需要企业构建时,您需要选择一个项目 XYZ,构建机器人会假设该项目需要在下 checkout

https://myrepositioryurl/{$projectname}.

这非常严格,我想重新配置构建机器人,使项目可以位于不同的 URL 下。在由“buildbot start master”启动的构建器设置过程中,我们项目的配置文件被读取并存储在 ConfigParser 对象中。在下面的源代码中,它是 clzoptions var 和我想使用的 URL 应该是

https://mytesturl/XYZ.

对于项目 XYZ。 我现在在测试项目的“svnBaseURL”条目下添加了不同的 URL。现在我在创建构建器的 python 类中遇到了一些我不太理解的东西。首先是来源:

import os
import logging

from xcodebuild import xcodebuild
from projects import Projects

from buildbot.config import BuilderConfig
from buildbot.process.factory import BuildFactory
from buildbot.steps.source import SVN
from buildbot.steps.shell import ShellCommand, WithProperties
from buildbot.process.properties import Property


class builders(object):
    clzoptions = Projects().options


    def __init__(self):
        aProject = Projects()
        self.options = aProject.options


    def enterprise_checkout_url(self, curProjectName):
        return curProjectName

    def create_enterprise_builder(self):
        factory = BuildFactory()
        factory.addStep(ShellCommand(name='svn checkout',
                                     haltOnFailure=True,
                                     description='svn checkout',
                                     descriptionDone='svn checkout done',
                                     command=['svn', 'checkout', '--username', 'admin', self.enterprise_checkout_url(WithProperties('%(project)s')), '.']))



        builderConfig = BuilderConfig(name="foobuilder",
                                      category="OnDemand",
                                      slavenames=[ "buildslave01" ],
                                      factory=factory)
        return builderConfig



    def get_all_builders(self):
        builders = []

        builders.append(self.create_enterprise_builder())

        return builders

我已经把它分解为核心问题,里面还有更多的构建器。关键函数是 self.enterprise_checkout_url(WithProperties('%(project)s'))。

如果我在瀑布中使用项目名称“XYZ”调用该构建器,我会得到结果

svn checkout --username admin XYZ .

用于 Shell 命令。虽然这是无意义的,因为它不是一个 URL,但我发现 参数 curProjectName 的计算结果为“XYZ”。 到目前为止很容易,对吧?现在让我们更改该功能...

def enterprise_checkout_url(self, curProjectName):
  return builders.clzoptions.get("XYZ", "svnBaseURL"))

并得到

svn checkout --username admin https://mytesturl/XYZ .

这几乎就是我需要的东西,

https://mytesturl/XYZ

是正确的路径。但关键是不变的,我需要它是可变的。但至少我知道字典存在并且有 XYZ 的正确条目。

现在这个问题我根本不明白。

我们现在就试试

def enterprise_checkout_url(self, curProjectName):
      return builders.clzoptions.get(curProjectName, "svnBaseURL"))

哎呀,他不 build

ConfigParser.NoSectionError: No section: <buildbot.process.properties.WithProperties instance at 0x1073739e0>

好吧,在编译阶段curProjectName可能没有设置,怎么样:

def enterprise_checkout_url(self, curProjectName):
    projects = builders.clzoptions.sections()
    for project in projects:
      if project == curProjectName:
        return builders.clzoptions.get(project, "svnBaseURL" )

编译。 我正在获取所有项目,测试 curProjectName 是否正确,然后使用应等于 curProjectName 的项目 key 返回我的 svnBaseURL。 但我得到:

<type 'exceptions.TypeError'>: 'NoneType' object is not iterable

轮到你了。我尝试在 curProjectName 上使用 str()、repr()、eval(),但无济于事。我无法同时访问现有字典和 curProjectName。

最佳答案

这对你有帮助吗?

class builders(object):

    builders = []
    print 'id of buiders just created ==',id(builders)

    def __init__(self,x):
        self.the = x

    def enterprise_checkout_url(self, curProjectName):
        return curProjectName

    def create_enterprise_builder(self,yy):
        builderConfig = dict(descriptionDone='-SVN-',
                             command=yy)
        return builderConfig

    def get_all_builders(self):
        print 'id of builders inside get_all_builders ==',id(builders)
        print 'id of builders.builders inside get_all_builders ==',id(builders.builders)

        builders.builders.append(self.create_enterprise_builder((self.the)))

        return builders.builders

print 'id of class builders ==',id(builders)
print '\n################################\n'

b = builders('BOF')
print b.get_all_builders()

print '\n=================================\n'

b2 = builders('MOTO')
print b2.get_all_builders()

结果

id of buiders just created == 18709040
id of class builders == 13819408

################################

id of builders inside get_all_builders == 13819408
id of builders.builders inside get_all_builders == 18709040
[{'descriptionDone': '-SVN-', 'command': 'BOF'}]

=================================

id of builders inside get_all_builders == 13819408
id of builders.builders inside get_all_builders == 18709040
[{'descriptionDone': '-SVN-', 'command': 'BOF'}, {'descriptionDone': '-SVN-', 'command': 'MOTO'}]

编辑

我的代码有问题。
如果执行两次print b2.get_all_builders()指令,结果为

id of buiders just created == 18709040
id of class builders == 13819408

################################

id of builders inside get_all_builders == 13819408
id of builders.builders inside get_all_builders == 18709040
[{'descriptionDone': '-SVN-', 'command': 'BOF'}]

=================================

id of builders inside get_all_builders == 13819408
id of builders.builders inside get_all_builders == 18709040
[{'descriptionDone': '-SVN-', 'command': 'BOF'}, {'descriptionDone': '-SVN-', 'command': 'MOTO'}]

id of builders inside get_all_builders == 13819408
id of builders.builders inside get_all_builders == 18709040
[{'descriptionDone': '-SVN-', 'command': 'BOF'}, {'descriptionDone': '-SVN-', 'command': 'MOTO'}, {'descriptionDone': '-SVN-', 'command': 'MOTO'}]

其中一本词典出现了两次。

由于我不太了解你的问题,并且不确定你到底想要什么,所以我不知道如何纠正它

关于python - 奇怪的 buildbot python 行为,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13706654/

相关文章:

python - 将 Lat Lon 坐标添加到单独的列(python/dataframe)

python - 根据条件过滤元组列表

python - 从字符串中过滤字符

python - 我如何任意告诉 Buildbot 不要为给定的更改安排构建?

git 提交队列工具

docker - Buildmaster 不监听端口

buildbot - 自定义 buildbot webstatus

python - 查找并删除文件中的重复行(最快、最有效的方法)

python - 每个文件一个类导致 python 中的双名