To deregister the custom job, we just need to call the DeleteJob
method on the job service. For this, you will need to have the JobId
of the job definition.
var tfsUri = new Uri("http://localhost:8080/tfs"); var config = TfsConfigurationServerFactory.GetConfigurationServer(tfsUri); var jobService = config.GetService<ITeamFoundationJobService>(); jobService.DeleteJob(new Guid("62FDDA25-4938-4BF7-A7C3-6A9BF527A20C"));
After running this, the custom job will be deregistered from the TFS job agent. Because you need the ID of the job to deregister it, you are able to set a static JobId when first registering the job. This way, you will not need to query the jobs to get the JobId
when you want to remove it.
If you run this code and then re-run the SQL from earlier in this chapter to check the installation and history of our job, you will get two empty results.