Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/278.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
更新目录时运行Python脚本_Python_Jenkins_Jenkins Plugins - Fatal编程技术网

更新目录时运行Python脚本

更新目录时运行Python脚本,python,jenkins,jenkins-plugins,Python,Jenkins,Jenkins Plugins,我有一个脚本,我想在特定目录更新时执行它。更具体地说:开发团队有4个目录(比如“a”、“b”、“c”和“d”),它们会不时更新。我有一个脚本,作为目录的参数名。我希望在更新目录“a”时使用参数“a”执行此脚本。有可能和詹金斯一起吗?如果是这样,我可以使用SVN做同样的事情吗?您可以使用python本身,使用watchdog库来做这件事 from watchdog.observers import Observer from watchdog.events import PatternMatc

我有一个脚本,我想在特定目录更新时执行它。更具体地说:开发团队有4个目录(比如“a”、“b”、“c”和“d”),它们会不时更新。我有一个脚本,作为目录的参数名。我希望在更新目录“a”时使用参数“a”执行此脚本。有可能和詹金斯一起吗?如果是这样,我可以使用SVN做同样的事情吗?

您可以使用python本身,使用
watchdog
库来做这件事

from watchdog.observers import Observer  
from watchdog.events import PatternMatchingEventHandler 

class FileHandler(PatternMatchingEventHandler):
    def process(self, event):
        print event.src_path, event.event_type  # print now only for degug

    def on_modified(self, event):
        self.process(event)

    def on_created(self, event):
        self.process(event)

if __name__ == '__main__':
    args = sys.argv[1:]
    observer = Observer()
    observer.schedule(MyHandler(), path=args[0] if args else '.')
    observer.start()

    try:
        while True:
            time.sleep(1)
    except KeyboardInterrupt:
        observer.stop()

    observer.join()

与python无关。Jenkins必须有一个SVN插件可以做到这一点。谢谢你的回答,这可能真的很有帮助!然而,我不确定它是否比使用詹金斯更好。这些目录位于服务器中,所以我可能应该在服务器端运行这个脚本,我不想这样做。更重要的是,我不希望它一直工作,我希望有一个简单的开关来运行或停止Jenkins有一个插件来完成这项工作,它可以查找文件系统的更改并触发构建。但是支持到此为止,我不确定它是否可以将更改后的目录名传递给脚本。