diff --git a/tests/cloud_playbooks/roles/packet-ci/defaults/main.yml b/tests/cloud_playbooks/roles/packet-ci/defaults/main.yml
index aad35de0ebd41ba127ea86de335aaf38f7d35b84..17dd3d8b9927afbb4799668f52ac248b9c53ead0 100644
--- a/tests/cloud_playbooks/roles/packet-ci/defaults/main.yml
+++ b/tests/cloud_playbooks/roles/packet-ci/defaults/main.yml
@@ -6,6 +6,9 @@ vm_cpu_sockets: 1
 vm_cpu_threads: 2
 vm_memory: 2048Mi
 
+# Replace invalid characters so that we can use the branch name in kubernetes labels
+branch_name_sane: "{{ branch | regex_replace('/', '-') }}"
+
 # Request/Limit allocation settings
 
 cpu_allocation_ratio: 0.5
diff --git a/tests/cloud_playbooks/roles/packet-ci/tasks/cleanup-old-vms.yml b/tests/cloud_playbooks/roles/packet-ci/tasks/cleanup-old-vms.yml
index cf81e81b5b0debee3697fc8ca25161433905441f..052a44fd170d233021aafeab00dc1a7e359b45b0 100644
--- a/tests/cloud_playbooks/roles/packet-ci/tasks/cleanup-old-vms.yml
+++ b/tests/cloud_playbooks/roles/packet-ci/tasks/cleanup-old-vms.yml
@@ -6,7 +6,7 @@
     kind: Namespace
     label_selectors:
       - cijobs = true
-      - branch = {{ branch }}
+      - branch = {{ branch_name_sane }}
   register: namespaces
 
 - name: Delete older namespaces
diff --git a/tests/cloud_playbooks/roles/packet-ci/tasks/create-vms.yml b/tests/cloud_playbooks/roles/packet-ci/tasks/create-vms.yml
index 688b580cd1e66685dd83c611418adcafb4074c70..4070b240266b8c2a9c366d0968c136d542463426 100644
--- a/tests/cloud_playbooks/roles/packet-ci/tasks/create-vms.yml
+++ b/tests/cloud_playbooks/roles/packet-ci/tasks/create-vms.yml
@@ -3,7 +3,7 @@
 - name: "Create CI namespace {{ test_name }} for test vms"
   shell: |-
     kubectl create namespace {{ test_name }} &&
-      kubectl label namespace {{ test_name }} cijobs=true branch="{{ branch }}" pipeline_id="{{ pipeline_id }}"
+      kubectl label namespace {{ test_name }} cijobs=true branch="{{ branch_name_sane }}" pipeline_id="{{ pipeline_id }}"
   changed_when: false
 
 - name: "Create temp dir /tmp/{{ test_name }} for CI files"