π§Ή [ko] How to disable automatic cleanup in jenkins?
μ ν¨μ€ auto - Workspace disable νλλ²
Jenkins automatically cleans up old workspaces using WorkspaceCleanupThread to manage disk space. This happens periodically, even without the cleanWs() command in your pipeline, ensuring efficient disk space usage.
Jenkins workspace
μ ν¨μ€(Jenkins) μμλ κ°κ°μ job build process λ§λ€ κ³ μ ν workspace μ μμ±νμ¬ μ¬μ©ν©λλ€.
workspace μλ build μ νμν νμΌλ€μ΄ μ μ₯λλ©°,
μ¬λ¬ λ²μ μ€νμλ λ 립μ μΈ νκ²½μμ build κ° κ°λ₯νλλ‘ μ 곡ν΄μ€λλ€.
workspace μ μ μ¬λλ νμΌμ ν¬κΈ°κ° ν° κ²½μ°,
jenkins server μ disk κ° κ°λ μ°° μ μλ λ¬Έμ κ° λ°μν μ μμ΅λλ€.
μ΄λ₯Ό λ°©μ§νκΈ° μν΄,
νμ΄νλΌμΈμ cleanWs()
λͺ
λ Ήμ΄λ₯Ό μΆκ°νμ¬ κ° build process λ§λ€ workspace λ₯Ό μ§μμ£Όλ μμ
μ μ ν/νννλλ‘ μ€μ ν μ μμ£ .
workspace λ₯Ό μ μ§νκ³ μΆλ€λ©΄ cleanWs()
λ₯Ό μ¬μ©νμ§ μμΌλ©΄ λ κ²λ§ κ°μ§λ§,
μ€μ λ‘λ μΌμ μ£ΌκΈ°κ° μ§λλ©΄ μ€λλ workspace λ μ€μ€λ‘ μ κ±°λ©λλ€.
μ΄μ νκ²½μμ λμνκ³ μλ jenkins job μ€ μΌλΆλ νμ΄νλΌμΈμ cleanWs() λ₯Ό μ¬μ©νκ³ μμ§ μμμ΅λλ€.
κ·ΈλΌμλ console log λ₯Ό 보면 clean workspace λ₯Ό μλν κ²μ νμΈν μ μμμ£ .
μ μ΄λ κ² λμνλ μ§, μ΄ν΄λ³΄μμ΅λλ€.
WorkspaceCleanupThread
μμΉν΄λ³΄λ μ ν¨μ€ μμ€ν λ΄μμ μ£ΌκΈ°μ μΌλ‘ workspace λ₯Ό cleanup νμ¬, μ ν¨μ€ μλ²μ disk 곡κ°μ κ΄λ¦¬νλ€κ³ ν©λλ€.
κ΄λ ¨ μΈλΆ λ‘μ§μ WorkspaceCleanupThread.java
μμ νμΈν μ μμμ΅λλ€.
μ£ΌμκΉκ² νμΈν΄μΌ νλ λΆλΆμλ βοΈμ΄λͺ¨μ§λ₯Ό λ¬μλμμ΅λλ€.
/**
* Clean up old left-over workspaces from agents.
*
* @author Kohsuke Kawaguchi
*/
@Extension @Symbol("workspaceCleanup")
public class WorkspaceCleanupThread extends AsyncPeriodicWork {
// ... μλ΅ ...
@Override protected void execute(TaskListener listener) throws InterruptedException, IOException {
if (disabled) { <------ βοΈ
LOGGER.fine("Disabled. Skipping execution");
return;
}
// ... μλ΅ ...
for (TopLevelItem item : j.allItems(TopLevelItem.class)) {
if (item instanceof ModifiableTopLevelItemGroup) { // no such thing as TopLevelItemGroup, and ItemGroup offers no access to its type parameter
continue; // children will typically have their own workspaces as subdirectories; probably no real workspace of its own
}
listener.getLogger().println("Checking " + item.getFullDisplayName());
for (Node node : nodes) {
FilePath ws = node.getWorkspaceFor(item);
if (ws == null) {
continue; // offline, fine
}
boolean check;
try {
check = shouldBeDeleted(item, ws, node); <------ βοΈ
} catch (IOException | InterruptedException x) {
Functions.printStackTrace(x, listener.error("Failed to check " + node.getDisplayName()));
continue;
}
if (check) { <------ βοΈ
listener.getLogger().println("Deleting " + ws + " on " + node.getDisplayName());
try {
ws.deleteRecursive(); <------ βοΈ
WorkspaceList.tempDir(ws).deleteRecursive(); <------ βοΈ
} catch (IOException | InterruptedException x) {
Functions.printStackTrace(x, listener.error("Failed to delete " + ws + " on " + node.getDisplayName()));
}
}
}
}
}
private boolean shouldBeDeleted(@Nonnull TopLevelItem item, FilePath dir, @Nonnull Node n) throws IOException, InterruptedException {
// ... μλ΅ ...
if(dir.lastModified() + retainForDays * DAY > now) { <------ βοΈ
LOGGER.log(Level.FINE, "Directory {0} is only {1} old, so not deleting", new Object[] {dir, Util.getTimeSpanString(now-dir.lastModified())});
return false;
}
// ... μλ΅ ...
return true;
}
/**
* Can be used to disable workspace clean up. <------ βοΈ
*/
public static boolean disabled = SystemProperties.getBoolean(WorkspaceCleanupThread.class.getName()+".disabled");
/**
* How often the clean up should run. This is final as Jenkins will not reflect changes anyway. <------ βοΈ
*/
public static final int recurrencePeriodHours = SystemProperties.getInteger(WorkspaceCleanupThread.class.getName()+".recurrencePeriodHours", 24);
/**
* Number of days workspaces should be retained. <------ βοΈ
*/
public static int retainForDays = SystemProperties.getInteger(WorkspaceCleanupThread.class.getName()+".retainForDays", 30);
}
μ μ½λλ₯Ό ν΅ν΄ μ μ μλ μ μ μ 리ν΄λ³΄μμ΅λλ€.
- recurrencePeriodHours μ£ΌκΈ°λ§λ€ workspace clean up μ μν (κΈ°λ³Έκ°: 24 μκ°)
- μμ ν΄μΌ ν workspace λ₯Ό νλ¨νλ κΈ°μ€μ, λ§μ§λ§ μμ μκ°μ΄ retainForDays λ³΄λ€ μ€λλμλμ§λ₯Ό μ²΄ν¬ (κΈ°λ³Έκ°: 30 μΌ)
μ ν¨μ€ job νμ΄νλΌμΈμμ cleanWs() λ₯Ό μ¬μ©νμ§ μλλΌλ, μ ν¨μ€ μλ²μμ workspace λ₯Ό clean up νλ €κ³ ν μ΄μ λ μ΄μ λΆλͺ ν΄μ‘μ£ .
λ§μ½, WorkspaceCleanupThread μ μν workspace clean up μ΄ μΌμ΄λμ§ μλλ‘ λ°©μ§νλ €λ©΄ μ΄λ»κ² ν΄μΌ ν κΉμ?
WorkspaceCleanupThread.java
μ½λλ₯Ό λ€μ νμΈν΄λ΄
μλ€.
@Override protected void execute(TaskListener listener) throws InterruptedException, IOException {
if (disabled) { <------ βοΈ
LOGGER.fine("Disabled. Skipping execution");
return;
}
// ... μλ΅ ...
}
/**
* Can be used to disable workspace clean up. <------ βοΈ
*/
public static boolean disabled = SystemProperties.getBoolean(WorkspaceCleanupThread.class.getName()+".disabled");
disabled
κ°μ λ°λΌμ λ‘μ§μ΄ μνλλ κ²μ μ μ μκ³ , ν΄λΉ κ°μ νκ²½ λ³μλ‘ μ λ¬λ°μΌλ―λ‘
Jenkins μμ μ,
-Dhudson.model.WorkspaceCleanupThread.disable=true
λ₯Ό μΆκ°νμ¬ workspace clean up μ λΉνμ±ν ν μ μμ΅λλ€.
μλͺ»λ λΆλΆμ΄ μλ€λ©΄ comment λ¨κ²¨μ£ΌμΈμ!
Leave a comment