如何以编程方式触发清理?
How to programmatically trigger cleanup?
我的构建服务器非常繁忙。在美好的一天,我们创造了将近 200gb 的工件。清理策略可以是 运行 一天一次,这对我来说是不够的。我搜索了 teamcity 文档并找到了零个 API 端点来支持手动触发清理。
是否可以从 script/program 手动触发清理?如何实现?
在最坏的情况下,我可以摆弄并跟踪手动强制清理时发生的情况,但它的道路很乱,我不想继续下去。
这里还有 C# 版本
void Main()
{
var cookieContainer = new CookieContainer();
var baseAddress = new Uri("http://teamcity");
var contentDictionary = new Dictionary<string,string>();
contentDictionary["cleanupPageAction"]= "startCleanup";
using (var handler = new HttpClientHandler() { CookieContainer = cookieContainer,
Credentials = new NetworkCredential("user","password","domain")})
using (var client = new HttpClient(handler) { BaseAddress = baseAddress })
{
var content = new FormUrlEncodedContent(contentDictionary);
var result = client.PostAsync("/admin/cleanupPolicies.html", content).Result;
result.EnsureSuccessStatusCode();
}
}
API 中没有此端点。如果您确实决定使用相同的 HTTP POST 仪表板用于手动清理的相同 HTTP,我认为这很简单:
curl -d "cleanupPageAction=startCleanup" \
http://user:password@builds.company.com/admin/cleanupPolicies.html
我的构建服务器非常繁忙。在美好的一天,我们创造了将近 200gb 的工件。清理策略可以是 运行 一天一次,这对我来说是不够的。我搜索了 teamcity 文档并找到了零个 API 端点来支持手动触发清理。
是否可以从 script/program 手动触发清理?如何实现?
在最坏的情况下,我可以摆弄并跟踪手动强制清理时发生的情况,但它的道路很乱,我不想继续下去。
这里还有 C# 版本
void Main()
{
var cookieContainer = new CookieContainer();
var baseAddress = new Uri("http://teamcity");
var contentDictionary = new Dictionary<string,string>();
contentDictionary["cleanupPageAction"]= "startCleanup";
using (var handler = new HttpClientHandler() { CookieContainer = cookieContainer,
Credentials = new NetworkCredential("user","password","domain")})
using (var client = new HttpClient(handler) { BaseAddress = baseAddress })
{
var content = new FormUrlEncodedContent(contentDictionary);
var result = client.PostAsync("/admin/cleanupPolicies.html", content).Result;
result.EnsureSuccessStatusCode();
}
}
API 中没有此端点。如果您确实决定使用相同的 HTTP POST 仪表板用于手动清理的相同 HTTP,我认为这很简单:
curl -d "cleanupPageAction=startCleanup" \
http://user:password@builds.company.com/admin/cleanupPolicies.html