-
Notifications
You must be signed in to change notification settings - Fork 35
RemoteTc
RemoteTc the single entry point for all the TeamCity REST API methods with fluent API. Below are some examples for using the FluentTc with its RemoteTc class. For full list of possibilities, explore it installing the package. You'll be surprised how easy it is!
Connecting to TeamCity as a guest
IConnectedTc connectedTc = new RemoteTc().Connect(a => a.ToHost("tc")
.AsGuest())
Connecting to TeamCity as specific user
IConnectedTc connectedTc = new RemoteTc().Connect(a => a.ToHost("tc")
.AsUser("MYUSERNAME", "MYPASSWORD"))
Get all projects
var allProjects = connectedTc.GetAllProjects();
Get project by Id
var project = connectedTc.GetProjectById("FluentTc");
Create project with specific Name
var project = connectedTc.CreateProject(_ => _.Name("New Project Name"));
Create sub project with Id and Name
project = connectedTc
.CreateProject(_ =>
_.Name("New Project Name")
.Id("newProjectId")
.ParentProject(a => a.Name("FluentTc")));
Set project parameter
connectedTc.SetProjectParameters(
_ => _.Id("ProjectId"),
__ => __.Parameter("param1", "value1"));
Set project's name and description
connectedTc.SetProjectConfigurationField(
having => having.Id("ProjectId"),
fields => fields.Name("New Name")
.Description("New description));
Move project to archive
connectedTc.SetProjectConfigurationField(
having => having.Id("ProjectId"),
fields => fields.Arvchive());
Get build configuration by Id
BuildConfiguration buildConfiguration = conntectedTc.GetBuildConfiguration(_ => _.Id("bt2"));
Get all the build configurations under a specific project
BuildConfiguration buildConfigurations = connectedTc.GetBuildConfigurations(
_ => _.Project(__ => __.Id("Trunk")));
Get all the build configurations under a project recursively
IList<BuildConfiguration> buildConfigurations = connectedTc.GetBuildConfigurations(
_ => _.ProjectRecursively(__ => __.Id("Trunk")));
Set build parameters on build configuration by its Id
connectedTc.SetBuildConfigurationParameters(
_ => _.Id("bt2"),
_ => _.Parameter("name", "value")
.Parameter("name2", "value"));
Set build configuration's name and description
connectedTc.SetBuildConfigurationField(
_ => _.Id("BuildId"),
__ => __.Name("New name")
.Description(description));
Pause build configuration
connectedTc.SetBuildConfigurationField(
_ => _.Id("BuildId"),
__ => __.Paused());
Unpause build configuration
connectedTc.SetBuildConfigurationField(
_ => _.Id("BuildId"),
__ => __.NotPaused());
Run build configuration by its Id
connectedTc.RunBuildConfiguration(_ => _.Id("bt2"));
Run build configuration by its Id with custom build parameters
connectedTc
.RunBuildConfiguration(_ => _.Id("bt2"),
_ => _.Parameter("name", "value").Parameter("name2", "value"));
Run build configuration by its Id on specific agent
connectedTc
.RunBuildConfiguration(
having => having.Id("bt2"),
onAgent => onAgent.Name("agent1"));
Run build configuration by its Id on on branch
connectecTc
.RunBuildConfiguration(
having => having.Id("bt2"),
custom => custom.OnBranch("develop"));
Run build configuration by its Id on on branch
connectecTc
.RunBuildConfiguration(
having => having.Id("bt2"),
custom => custom.OnBranch("develop"));
Run build configuration by its Id on develop branch, with comment, as personal build, queue on top, rebuild all dependencies and clean sources
connectecTc
.RunBuildConfiguration(
having => having.Id("bt2"),
custom => custom.OnBranch("develop")
.WithComment("personal build on develop")
.AsPersonal()
.QueueAtTop()
.RebuildAllDependencies()
.WithCleanSources());
Create build configuration under a project
BuildConfiguration buildConfiguration = connectecTc.CreateBuildConfiguration(
_ => _.Id("Trunk"), "config name");
Attach build configuration to template
connectedTc.AttachBuildConfigurationToTemplate(
_ => _.Name("FluentTc"),
"BuildTemplateId");
Get investigation of build configuration by its Id
Investigation investigation = connectedTc
.GetInvestigation(_ => _.Id("fluentTc"));
Create a VCS root using anonymous authentication
VcsRoot vcsRoot = connectedTc.CreateVcsRoot(vcsRoot => vcsRoot
.AgentCleanFilePolicy(AgentCleanFilePolicy.AllIgnoredUntrackedFiles)
.AgentCleanPolicy(AgentCleanPolicy.Always)
.AuthMethod(AuthMethod.Anonymous)
.Branch("refs/head/develop")
.BranchSpec("+:refs/head/feature/*")
.Id("VcsRootId")
.IgnoreKnownHosts()
.Name("VcsRootName")
.Password("Password")
.ProjectId("FluentTc")
.CheckoutSubModule()
.Url(new Uri("https://github.com/QualiSystems/FluentTc.git"))
.UseAlternates()
.Username("borismod")
.UserNameStyle(UserNameStyle.AuthorName));
**Create a VCS root with SSH authentication **
VcsRoot vcsRoot = connectedTc.CreateVcsRoot(__ => __
.ProjectId("ProjectId")
.Id("VcsRootId")
.Name("VcsRootName")
.AuthMethod(AuthMethod.TeamcitySshKey)
.TeamcitySshKey("keyName");
Attach VCS root to build configuration
connectedTc.AttachVcsRootToBuildConfiguration(
buildConfiguration => buildConfiguration.Id("BuildId"),
vcsRoot => vcsRoot.Id(vcsRoot.Id)
.CheckoutRules("*=>src"));
Get specific build by ID (with all the properties)
Build build = connectedTc.GetBuild(_ => _.Id(123456));
Get builds triggered by user
List<Build> builds = connectedTc.GetBuilds(
_ => _.TriggeredBy(
__ => __.Username(Username)))
Get not personal builds, under build configuration bt2, under project OpenSourceProject, that ran on agent Agent01 on branch master
List<Build> builds = connectedTc
.GetBuilds(
h =>
h.BuildConfiguration(r => r.Id("bt2"))
.NotPersonal()
.Project(r => r.Name("OpenSourceProject"))
.AgentName("Agent01")
.Branch(b => b.Name("master")));
Get personal builds with additional properties: StartDate, FinishDate and StatusText
builds = connectedTc.GetBuilds(_ => _.Personal(),
_ => _.IncludeStartDate()
.IncludeFinishDate()
.IncludeStatusText());
Get 5 personal builds with default properties
builds = connectedTc.GetBuilds(_ => _.Personal(),
_ => _.IncludeDefaults(),
_ => _.Count(5));
Get 5 not personal builds from build configuration bt2 with default properties
builds = connectedTc.GetBuilds(
_ => _.BuildConfiguration(x => x.Id("bt2"))
.NotPersonal().NotRunning(),
_ => _.IncludeDefaults(),
_ => _.Count(5));
Get last successful build by build configuration Id with changes
connectedTc.GetLastBuild(
_ => _.BuildConfiguration(__ => __.Id("FluentTc"))
.Status(BuildStatus.Success),
__ => __.IncludeChanges(c => c.IncludeComment()
.IncludeFiles()
.IncludeVcsRootInstance()));
Disable agent by IP
connectedTc.DisableAgent(_ => _.Ip("127.0.0.1"));
Enable agent by name
connectedTc.EnableAgent(_ => _.Name("agent1"));
Get connected agents
var agents = connectedTc.GetAgents(
_ => _.Connected());
Get disconnected, enabled and authorized agents
var enabledAuthorizedButDisconnectedAgents = connectedTc.GetAgents(
_ => _.Disconnected()
.Enabled()
.Authorized());
Get builds queue
List<Build> buildQueue = connectedTc.GetBuildsQueue();
Get builds queue from specific project by its Id
var buildQueue = connectedTc.GetBuildsQueue(
_ => _.Project(
__ => __.Id("OpenSourceProject")));
Get builds queue from specific project by its ID and build configuration name
var buildQueue2 = connectedTc
.GetBuildsQueue(
__ =>
__.Project(___ => ___.Id("OpenSourceProject"))
.BuildConfiguration(b => b.Name("FluentTc")));
Remove builds from queue by project Id recursively
connectedTc.GetBuildConfigurationsRecursively("ProjectId")
.ForEach(c => connectedTc.RemoveBuildFromQueue(
__ => __.BuildConfiguration(___ => ___.Id(c.Id))));
Download artifacts of latest successful build
IBuild lastSuccessfulBuild = connectedTc.GetLastBuild(having =>
having.BuildConfiguration(with => with.Id("FluentTc"))
.Status(BuildStatus.Success))
IList<string> downloadedFiles = connectedTc.DownloadArtifacts(lastSuccessfulBuild.Id,
@"C:\DownloadedArtifacts");
Download artifacts
List<string> downloadedFiles = connectedTc.DownloadArtifacts(123, @"C:\DownloadedArtifacts");
Download specific file from artifacts
string downloadedFile = connectedTc.DownloadArtifacts(123, @"C:\DownloadedArtifacts", "binaries.zip");
Get all users
List<User> users = connectedTc.GetAllUsers();
Get user by username
User user = connectedTc.GetUser(_ => _.Username("borismod"))