Skip to content

Commit

Permalink
Refactor to allow easier tag usage
Browse files Browse the repository at this point in the history
  • Loading branch information
cailafinn committed Jan 14, 2025
1 parent d1096bc commit e9ffa94
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 35 deletions.
37 changes: 33 additions & 4 deletions Linux/jenkins-node/ansible/clean-jenkins-agents.yml
Original file line number Diff line number Diff line change
@@ -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]
8 changes: 4 additions & 4 deletions Linux/jenkins-node/ansible/readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
27 changes: 0 additions & 27 deletions Linux/jenkins-node/ansible/roles/clean-agent/tasks/main.yml

This file was deleted.

0 comments on commit e9ffa94

Please sign in to comment.