1

我有一个创建工件的 GoCD 管道。有什么办法可以让我拉上一次运行的工件与当前运行进行比较?

4

1 回答 1

1

您可以使用yagocd库执行此操作:

#!/usr/bin/env python

import logging

from yagocd import Yagocd

if __name__ == '__main__':
    logging.basicConfig(level=logging.DEBUG)
    logging.getLogger("requests").setLevel(logging.WARNING)

    go = Yagocd(
        server='https://build.gocd.io',
        # auth=('username', 'password'),
    )

    # login as guest
    go._session.get('https://build.gocd.io/go/plugin/interact/gocd.guest.user.auth.plugin/index')

    pipeline = go.pipelines['plugins']
    last_instance, previous_to_last = pipeline.history()[:2]

    last_artifacts = list()
    previous_to_last_artifacts = list()

    for stage in last_instance:
        for job in stage:
            for root, folder, files in job.artifacts:
                for artifact in files:
                    last_artifacts.append(artifact)

    for stage in previous_to_last:
        for job in stage:
            for root, folder, files in job.artifacts:
                for artifact in files:
                    previous_to_last_artifacts.append(artifact)

    # Now you can compare artifacts
    # how you like: either calculate set diff
    # or review content difference via `artifact.fetch()` method.
于 2017-05-08T19:10:34.200 回答