Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Delete older than 14 days #3050

Merged
merged 11 commits into from
Feb 14, 2025
Merged

Delete older than 14 days #3050

merged 11 commits into from
Feb 14, 2025

Conversation

rasapala
Copy link
Collaborator

@rasapala rasapala commented Feb 10, 2025

🛠 Summary

JIRA [CVS-161260
Delete PR-XXXX older than 14 days on jenkins nodes.

🧪 Checklist

  • Unit tests added.
  • The documentation updated.
  • Change follows security best practices.
    ``

@rasapala rasapala requested a review from dtrawins February 11, 2025 12:57
// Sanity check not to delete anything else
if (!pathToDelete.contains("c:\\pr-")) {
if (!pathToDelete.contains("C:\\PR-")) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why those fixes? does it mean we never deleted directories after PR is closed?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have added changes to make sure its uppercase.

command = 'forfiles /P c:\\ /D -14 | grep -oE "(PR-[0-9]*)"'
status = bat(returnStatus: true, script: command)
if ( status != 0) {
println "No PR-XXXX older than 14 days for cleanup."
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

will one be re-created when someone continues the work on 14 days old PR?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, It will take longer as the bazel cache will need to be downloaded once again.

@@ -11,7 +13,7 @@ def cleanup_directories() {
println existing_workspace_string
def existing_workspace = existing_workspace_string.split(/\n/)

command = 'ls c:\\ | grep -oE "(pr-[0-9]*)$"'
command = 'ls c:\\ | grep -oE "(PR-[0-9]*)$"'
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if we have no idea why pr changed to PR, then its good to consider both options in all scripts

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added toUpper from jenkins env.

for (int i = 0; i < existing_prs.size(); i++) {
// Check for empty output, Part of output contains the command that was run
if ( existing_prs[i] == null || existing_prs[i].allWhitespace || existing_prs[i].toLowerCase().contains("grep")) { continue }
// Check if directory was created more than 14 days ago
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is this comment here? Doesn't existing_prs contain only 14 days long dirs?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Windows command return the executed command and forfiles as a loop returns empty/null string at the beginning and end of output.

Copy link
Collaborator Author

@rasapala rasapala left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

resp

@rasapala rasapala merged commit 870df4f into main Feb 14, 2025
13 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants