diff --git a/.buildkite/local-pipeline.yml b/.buildkite/local-pipeline.yml index d532c27..36643f7 100644 --- a/.buildkite/local-pipeline.yml +++ b/.buildkite/local-pipeline.yml @@ -9,4 +9,5 @@ steps: p4user: banana view: //depot/... ... root: p4_workspace - parallel: 2 \ No newline at end of file + parallel: 2 + backup_changelists: yes \ No newline at end of file diff --git a/plugin.yml b/plugin.yml index 71b7509..a54cf7c 100644 --- a/plugin.yml +++ b/plugin.yml @@ -22,4 +22,6 @@ configuration: parallel: type: string client_opts: - type: string + type: string + backup_changelists: + type: bool diff --git a/python/buildkite.py b/python/buildkite.py index a0b2aeb..aba476b 100644 --- a/python/buildkite.py +++ b/python/buildkite.py @@ -41,6 +41,9 @@ def get_config(): conf['view'] = ['%s %s' % (v, next(view_iter)) for v in view_iter] return conf +def should_backup_changelists(): + return os.environ.get('BUILDKITE_PLUGIN_PERFORCE_BACKUP_CHANGELISTS', 'false') == 'true' + def get_metadata(key): """If it exists, retrieve metadata from buildkite for a given key""" if not __ACCESS_TOKEN__ or __LOCAL_RUN__: diff --git a/python/checkout.py b/python/checkout.py index 4610c23..a804175 100644 --- a/python/checkout.py +++ b/python/checkout.py @@ -8,7 +8,8 @@ from perforce import P4Repo from buildkite import (get_env, get_config, get_build_revision, set_build_revision, - get_users_changelist, get_build_changelist, set_build_changelist, set_build_info) + get_users_changelist, get_build_changelist, set_build_changelist, set_build_info, + should_backup_changelists) def main(): """Main""" @@ -25,7 +26,7 @@ def main(): # Convert changelist number to revision specifier if re.match(r'^\d*$', revision): - revision = '@%d' % revision + revision = '@%s' % revision repo.sync(revision=revision) @@ -37,7 +38,9 @@ def main(): # Use existing or make a copy of the users changelist for this build changelist = get_build_changelist() if not changelist: - changelist = repo.backup(user_changelist) + changelist = user_changelist + if should_backup_changelists(): + changelist = repo.backup(user_changelist) set_build_changelist(changelist) repo.unshelve(changelist)