From 8d38d9c8431b0567486cd20c2f3cff3c8542d290 Mon Sep 17 00:00:00 2001 From: Fabien Boucher Date: Feb 25 2020 09:23:56 +0000 Subject: set-origin: add role to be used in post merge pipeline to set the remote In post-merge pipelines Zuul set a repository with origin remote set to /dev/null. This can be problematic in the packaging context where version number or target release are determined from the git context like git tags. --- diff --git a/roles/set-origin/defaults/main.yaml b/roles/set-origin/defaults/main.yaml new file mode 100644 index 0000000..e36abd2 --- /dev/null +++ b/roles/set-origin/defaults/main.yaml @@ -0,0 +1,3 @@ +--- +base_url: https://github.com +reset_branch: false diff --git a/roles/set-origin/tasks/main.yaml b/roles/set-origin/tasks/main.yaml new file mode 100644 index 0000000..a2dcc58 --- /dev/null +++ b/roles/set-origin/tasks/main.yaml @@ -0,0 +1,16 @@ +--- +# In post-merge post/promote pipelines Zuul set explicitly the origin to /dev/null +- name: Set origin and tracking branch + command: "{{ item }}" + args: + chdir: "{{ ansible_user_dir }}/{{ zuul.project.src_dir }}" + loop: + - git remote set-url origin {{ base_url }}/{{ zuul.project.name }} + - git branch -u origin/{{ zuul.branch }} + - git fetch origin + +- name: Reset project checkout to origin/branch + command: git reset --hard origin/{{ zuul.branch }} + args: + chdir: "{{ ansible_user_dir }}/{{ zuul.project.src_dir }}" + when: reset_branch