나는 주위에 작업 실행 :
가 먼저 콘솔 응용 프로그램을 작성을하고,이 빌드 단계에서 호출 될 것입니다 : 그것은에 RetainBuildIndefinitely.exe를 호출
private static void Main(string[] args)
{
// All this does is dispatch the call to a new process, so that the build can complete independently
// before attempting to update the keepForever field
// This is because you cannot update this field while the build is running
if (args.Length < 1)
{
throw new Exception("No Build Number Provided");
}
var buildId = args[0];
Console.WriteLine("Dispatching task to retain build: " + buildId);
var workingDir = Path.GetDirectoryName(Assembly.GetEntryAssembly().Location);
Console.WriteLine("Working Directory Set: " + workingDir);
if (workingDir == null)
{
throw new Exception("Working directory is null");
}
var p = new Process
{
StartInfo =
{
WorkingDirectory = workingDir,
FileName = "RetainBuildIndefinitely.exe",
Arguments = buildId,
RedirectStandardOutput = false,
UseShellExecute = true,
CreateNoWindow = false
}
};
p.Start();
}
지금 당신이 그것을 알 수 있습니다 자신의 프로세스. 이것은이 태스크를 디스패치하고 종료 한 다음 빌드를 완료 할 수 있도록하기위한 것입니다. 당신이 빌드에 http 동안 유사한 PowerShell 스크립트를 사용하는 경우 현상 무엇
namespace RetainBuildIndefinitely
{
public class WebApiCalls
{
public void RetainBuildIndefinately(string buildId)
{
// Max retry attempts
var retryCount = 30;
// The Tfs Url
var url = [YourURL eg: http://server:8080/tfs/TeamCollection/Project/_apis/build/builds/{buildId}?api-version=2.0";
// Poll until the build is finished
// Since this call should be made in the last build step, there shouldn't be too much waiting for this to complete
using (var client = new WebClient {UseDefaultCredentials = true})
{
client.Headers.Add("Content-Type", "application/json");
client.Encoding = Encoding.UTF8;
var completed = false;
var attempt = 1;
while (completed == false)
{
if (attempt == retryCount)
{
// Couldn't complete? Clearly something went very wrong
// TODO: Sent out a notification email, but to who?
return;
}
var source = client.DownloadString(url);
dynamic data = JObject.Parse(source);
if (data.status == "completed")
{
// Completed, let's move on!
completed = true;
}
attempt = attempt + 1;
Thread.Sleep(2000);
}
} ;
// Set the keepForever property
using (var client2 = new WebClient {UseDefaultCredentials = true})
{
client2.Headers.Add("Content-Type", "application/json");
client2.Encoding = Encoding.UTF8;
client2.UploadString(url, "PATCH", "{keepForever : true}");
}
}
}
}
:
그리고 구현 :
RetainBuildIndefinitely.exe는 콘솔 응용 프로그램입니다 // 유래 .com/questions/38583551/send-a-patch-request-from-ac-sharp-client? –
권한 오류가 발생했기 때문에 powershell 스크립트를 버렸지 만 C# 기능이 동일해야하므로 PS 스크립트가 작동했는지 확인할 수 없으므로 실제로는 그렇지 않습니다. –