I need to update a vNext Build Definition programmatically. The reason for the need to programmatically update the build definition is that we are running the RTM version of Team Foundation Server 2015, and as of that release certain parts of the vNext Build Definitions are not exposed to the web GUI, and there is (as yet) no other way to change them. (Assuming that you want to keep your database in a supported state, and refuse to modify the database directly.)
Our corporate environment and all machines recently went through a domain change. The TFS server was moved to the new domain with no issues. However, the vNext Build definition has an internal reference to the old server name in the URL field, which still has the old domain name inside it.
So far, I have the following code which should update the URL of each build definition of a certain project. The call to GetDefinitonsAsync clearly returns the proper build DefinitionReferences to me, but UpdateDefinitionAsync does not seem to have any effect.
List<DefinitionReference> bds = new List<DefinitionReference>();
.
.
.
{
Uri tfsURI = new Uri("http://<tfsserver>:8080/tfs/<collection>");
WindowsCredential wc = new WindowsCredential(true);
BuildHttpClient bhc = new BuildHttpClient(tfsURI, new VssCredentials(wc));
var task = Task.Run(async () => { bds = await bhc.GetDefinitionsAsync(project: "projectname"); });
task.Wait();
foreach (var bd in bds)
{
BuildDefinition b = (BuildDefinition)bd;
b.Url = b.Url.Replace("<server>.<olddomain>", "<server>.<newdomain>");
var task1 = Task.Run(async () => { await bhc.UpdateDefinitionAsync(b); });
task1.Wait();
}
}
This code snippet compiles and runs without error. However, when I examine the build definition afterward, it has not been updated and remains as before. There are no exceptions seen by the debugger, and there are no event viewer or DebugView messages of relevance.
Regarding the above code snippet, I am uncertain about whether I am suppose to obtain the BuildDefinition that I need to pass to UpdateDefinition by casting the DefinitionReference (subclass) to BuildDefinition or not, but I see nothing close in the BuildHttpClient class that will give me a BuildDefiniton from a DefinitonReference.
Any help would be appreciated. Thanks!
Best Answer
To elaborate on my last comment with code,
}