From e9ffa94d4c295637483bbfde7cffe70c70a8052d Mon Sep 17 00:00:00 2001 From: Caila Finn Date: Tue, 14 Jan 2025 15:39:08 +0000 Subject: [PATCH] Refactor to allow easier tag usage RE #103 --- .../ansible/clean-jenkins-agents.yml | 37 +++++++++++++++++-- Linux/jenkins-node/ansible/readme.md | 8 ++-- .../ansible/roles/clean-agent/tasks/main.yml | 27 -------------- 3 files changed, 37 insertions(+), 35 deletions(-) delete mode 100644 Linux/jenkins-node/ansible/roles/clean-agent/tasks/main.yml diff --git a/Linux/jenkins-node/ansible/clean-jenkins-agents.yml b/Linux/jenkins-node/ansible/clean-jenkins-agents.yml index 416a056..c377807 100644 --- a/Linux/jenkins-node/ansible/clean-jenkins-agents.yml +++ b/Linux/jenkins-node/ansible/clean-jenkins-agents.yml @@ -1,7 +1,36 @@ -- name: Clean jenkins agents by removing workspaces. +- name: Playbook to clean jenkins agents by removing workspaces. hosts: all # Tags available: pr, nightly, package, docs - roles: - - role: clean-agent - become: yes + tasks: + - name: Remove PR directories + community.docker.docker_container_exec: + container: "{{ agent_name }}" + command: bash -l -c "rm -rf pull_requests*" + chdir: "/jenkins_workdir/workspace" + become: yes + tags: [never, pr] + + - name: Remove Nightly directories + community.docker.docker_container_exec: + container: "{{ agent_name }}" + command: bash -l -c "rm -rf *_nightly_deployment*" + chdir: "/jenkins_workdir/workspace" + become: yes + tags: [never, nightly] + + - name: Remove Packages from Branch directories + community.docker.docker_container_exec: + container: "{{ agent_name }}" + command: bash -l -c "rm -rf build_packages_from_branch*" + chdir: "/jenkins_workdir/workspace" + become: yes + tags: [never, package] + + - name: Remove Docs Build directories + community.docker.docker_container_exec: + container: "{{ agent_name }}" + command: bash -l -c "rm -rf build_and_publish_docs*" + chdir: "/jenkins_workdir/workspace" + become: yes + tags: [never, docs] diff --git a/Linux/jenkins-node/ansible/readme.md b/Linux/jenkins-node/ansible/readme.md index 5c8bf0e..f21336b 100644 --- a/Linux/jenkins-node/ansible/readme.md +++ b/Linux/jenkins-node/ansible/readme.md @@ -38,21 +38,21 @@ ansible-playbook -i inventory.txt jenkins-agent-staging.yml -u FedID -K -t agent - Before cleaning any nodes mark them temporarily offline on Jenkins and ensure no jobs are running on them before cleaning. -- Update the `inventory.txt` file as above, including only the nodes you need to clean. +- Update the `inventory.txt` file as above, including only the nodes you intend to clean. -- The tasks in the cleaning role make use of tags to restrict what is cleaned: +- The tasks in the cleaning playbook make use of tags to restrict what is cleaned: - `pr`: Pull Requests. - `nightly`: Nightly deployments for main and release next. - `package`: Build Packages from Branch - `docs`: Docs build and publish. -- Run the following with the desired tags (which use a comma-separated list). **If no tags are provided all workspaces will be deleted.**: +- Run the following with the desired tags (which use a comma-separated list): ```sh ansible-playbook -i inventory.txt clean-jenkins-agents.yml -u FedID -K -t pr,nightly,package,docs ``` -- Mark the shutdown nodes back online. +- Set the nodes you shut down back online. ### Troubleshooting diff --git a/Linux/jenkins-node/ansible/roles/clean-agent/tasks/main.yml b/Linux/jenkins-node/ansible/roles/clean-agent/tasks/main.yml deleted file mode 100644 index 6525aee..0000000 --- a/Linux/jenkins-node/ansible/roles/clean-agent/tasks/main.yml +++ /dev/null @@ -1,27 +0,0 @@ -- name: Remove PR directories - community.docker.docker_container_exec: - container: "{{ agent_name }}" - command: bash -l -c "rm -rf pull_requests*" - chdir: "/jenkins_workdir/workspace" - tags: pr - -- name: Remove Nightly directories - community.docker.docker_container_exec: - container: "{{ agent_name }}" - command: bash -l -c "rm -rf *_nightly_deployment*" - chdir: "/jenkins_workdir/workspace" - tags: nightly - -- name: Remove Packages from Branch directories - community.docker.docker_container_exec: - container: "{{ agent_name }}" - command: bash -l -c "rm -rf build_packages_from_branch*" - chdir: "/jenkins_workdir/workspace" - tags: package - -- name: Remove Docs Build directories - community.docker.docker_container_exec: - container: "{{ agent_name }}" - command: bash -l -c "rm -rf build_and_publish_docs*" - chdir: "/jenkins_workdir/workspace" - tags: docs