Skip to content
This repository was archived by the owner on Feb 12, 2019. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
3577da0
Build.BuildById was added
borismod Jun 20, 2014
a6867cc
EasyHttp package upgraded, NugetPackages restore set
borismod Jun 23, 2014
2868b49
BuildById method was enhanced to retrieve changes as well
borismod Jun 23, 2014
ec69d58
TeamCityCaller.GetDownloadFormat fixed to support urlPart with string…
borismod Jun 28, 2015
60589a3
Changes.byBuildId was added
borismod Jun 28, 2015
4e1d630
TeamCityCaller.GetDownloadFormat throw exception if status not OK
borismod Jun 29, 2015
1fd53e4
BuildNumber was added in build locator
borismod Jul 7, 2015
3cdc6a7
BuildLocator Number was improved
borismod Jul 7, 2015
bdd5637
TestOccurrences was added on TestClient
borismod Jul 13, 2015
0d77f30
TestOccurrenceById was added
borismod Jul 19, 2015
af7ed6d
Changes.ByBuildId was fixed and Changes.ByBuildIdWithDetails was added
borismod Jul 20, 2015
4609312
Update README.md
borismod Jul 20, 2015
f1b6e4b
TestHistoryByTestId was added
borismod Aug 2, 2015
4c1ec9e
ByBuildIdWithDetails improved to handle builds with no changes
borismod Aug 11, 2015
7552eae
CopyBuildConfiguration was added on BuildConfigs
borismod Aug 20, 2015
00b8ca0
TriggerBuildConfiguration method was added on BuildConfig
borismod Aug 23, 2015
9f2372b
BuildConfig methods added and improved:
borismod Aug 26, 2015
e126b2c
BuildConfigs.TriggerBuildConfiguration with parameters was added
borismod Aug 27, 2015
2d6d496
UpdateName was added on BuildConfigs
borismod Aug 30, 2015
032490d
Update README.md
borismod Aug 30, 2015
0e93762
TriggerBuildConfiguration was added with agentId
borismod Sep 8, 2015
238246d
Merge branch 'master' of https://github.com/borismod/TeamCitySharp
borismod Sep 8, 2015
12f2be2
TriggerBuildConfiguration was added to interface
borismod Sep 8, 2015
320ef85
Update README.md
borismod Sep 8, 2015
65f2b81
Investigations were added with two methods: InvestigationsById and In…
borismod Sep 9, 2015
e8e2306
Merge branch 'master' of https://github.com/borismod/TeamCitySharp
borismod Sep 9, 2015
b929f03
Update README.md
borismod Sep 9, 2015
2aefaec
InvestigationByTest, InvestigationsByBuildConfiguration and Investiga…
borismod Sep 17, 2015
d9ee904
Merge branch 'master' of https://github.com/borismod/TeamCitySharp
borismod Sep 17, 2015
6c005f7
Overload method was added to Builds.ByBuildLocator that enables retri…
borismod Oct 1, 2015
73a0014
ByBuildLocator was added to IBuilds reference
borismod Oct 1, 2015
b603a26
EasyHttp.1.6.67.0 was upgraded to EasyHttp.1.6.86.0
borismod Apr 10, 2016
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions .nuget/NuGet.Config
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<solution>
<add key="disableSourceControlIntegration" value="true" />
</solution>
</configuration>
Binary file added .nuget/NuGet.exe
Binary file not shown.
144 changes: 144 additions & 0 deletions .nuget/NuGet.targets
Original file line number Diff line number Diff line change
@@ -0,0 +1,144 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<SolutionDir Condition="$(SolutionDir) == '' Or $(SolutionDir) == '*Undefined*'">$(MSBuildProjectDirectory)\..\</SolutionDir>

<!-- Enable the restore command to run before builds -->
<RestorePackages Condition=" '$(RestorePackages)' == '' ">false</RestorePackages>

<!-- Property that enables building a package from a project -->
<BuildPackage Condition=" '$(BuildPackage)' == '' ">false</BuildPackage>

<!-- Determines if package restore consent is required to restore packages -->
<RequireRestoreConsent Condition=" '$(RequireRestoreConsent)' != 'false' ">true</RequireRestoreConsent>

<!-- Download NuGet.exe if it does not already exist -->
<DownloadNuGetExe Condition=" '$(DownloadNuGetExe)' == '' ">false</DownloadNuGetExe>
</PropertyGroup>

<ItemGroup Condition=" '$(PackageSources)' == '' ">
<!-- Package sources used to restore packages. By default, registered sources under %APPDATA%\NuGet\NuGet.Config will be used -->
<!-- The official NuGet package source (https://www.nuget.org/api/v2/) will be excluded if package sources are specified and it does not appear in the list -->
<!--
<PackageSource Include="https://www.nuget.org/api/v2/" />
<PackageSource Include="https://my-nuget-source/nuget/" />
-->
</ItemGroup>

<PropertyGroup Condition=" '$(OS)' == 'Windows_NT'">
<!-- Windows specific commands -->
<NuGetToolsPath>$([System.IO.Path]::Combine($(SolutionDir), ".nuget"))</NuGetToolsPath>
</PropertyGroup>

<PropertyGroup Condition=" '$(OS)' != 'Windows_NT'">
<!-- We need to launch nuget.exe with the mono command if we're not on windows -->
<NuGetToolsPath>$(SolutionDir).nuget</NuGetToolsPath>
</PropertyGroup>

<PropertyGroup>
<PackagesProjectConfig Condition=" '$(OS)' == 'Windows_NT'">$(MSBuildProjectDirectory)\packages.$(MSBuildProjectName.Replace(' ', '_')).config</PackagesProjectConfig>
<PackagesProjectConfig Condition=" '$(OS)' != 'Windows_NT'">$(MSBuildProjectDirectory)\packages.$(MSBuildProjectName).config</PackagesProjectConfig>
</PropertyGroup>

<PropertyGroup>
<PackagesConfig Condition="Exists('$(MSBuildProjectDirectory)\packages.config')">$(MSBuildProjectDirectory)\packages.config</PackagesConfig>
<PackagesConfig Condition="Exists('$(PackagesProjectConfig)')">$(PackagesProjectConfig)</PackagesConfig>
</PropertyGroup>

<PropertyGroup>
<!-- NuGet command -->
<NuGetExePath Condition=" '$(NuGetExePath)' == '' ">$(NuGetToolsPath)\NuGet.exe</NuGetExePath>
<PackageSources Condition=" $(PackageSources) == '' ">@(PackageSource)</PackageSources>

<NuGetCommand Condition=" '$(OS)' == 'Windows_NT'">"$(NuGetExePath)"</NuGetCommand>
<NuGetCommand Condition=" '$(OS)' != 'Windows_NT' ">mono --runtime=v4.0.30319 "$(NuGetExePath)"</NuGetCommand>

<PackageOutputDir Condition="$(PackageOutputDir) == ''">$(TargetDir.Trim('\\'))</PackageOutputDir>

<RequireConsentSwitch Condition=" $(RequireRestoreConsent) == 'true' ">-RequireConsent</RequireConsentSwitch>
<NonInteractiveSwitch Condition=" '$(VisualStudioVersion)' != '' AND '$(OS)' == 'Windows_NT' ">-NonInteractive</NonInteractiveSwitch>

<PaddedSolutionDir Condition=" '$(OS)' == 'Windows_NT'">"$(SolutionDir) "</PaddedSolutionDir>
<PaddedSolutionDir Condition=" '$(OS)' != 'Windows_NT' ">"$(SolutionDir)"</PaddedSolutionDir>

<!-- Commands -->
<RestoreCommand>$(NuGetCommand) install "$(PackagesConfig)" -source "$(PackageSources)" $(NonInteractiveSwitch) $(RequireConsentSwitch) -solutionDir $(PaddedSolutionDir)</RestoreCommand>
<BuildCommand>$(NuGetCommand) pack "$(ProjectPath)" -Properties "Configuration=$(Configuration);Platform=$(Platform)" $(NonInteractiveSwitch) -OutputDirectory "$(PackageOutputDir)" -symbols</BuildCommand>

<!-- We need to ensure packages are restored prior to assembly resolve -->
<BuildDependsOn Condition="$(RestorePackages) == 'true'">
RestorePackages;
$(BuildDependsOn);
</BuildDependsOn>

<!-- Make the build depend on restore packages -->
<BuildDependsOn Condition="$(BuildPackage) == 'true'">
$(BuildDependsOn);
BuildPackage;
</BuildDependsOn>
</PropertyGroup>

<Target Name="CheckPrerequisites">
<!-- Raise an error if we're unable to locate nuget.exe -->
<Error Condition="'$(DownloadNuGetExe)' != 'true' AND !Exists('$(NuGetExePath)')" Text="Unable to locate '$(NuGetExePath)'" />
<!--
Take advantage of MsBuild's build dependency tracking to make sure that we only ever download nuget.exe once.
This effectively acts as a lock that makes sure that the download operation will only happen once and all
parallel builds will have to wait for it to complete.
-->
<MsBuild Targets="_DownloadNuGet" Projects="$(MSBuildThisFileFullPath)" Properties="Configuration=NOT_IMPORTANT;DownloadNuGetExe=$(DownloadNuGetExe)" />
</Target>

<Target Name="_DownloadNuGet">
<DownloadNuGet OutputFilename="$(NuGetExePath)" Condition=" '$(DownloadNuGetExe)' == 'true' AND !Exists('$(NuGetExePath)')" />
</Target>

<Target Name="RestorePackages" DependsOnTargets="CheckPrerequisites">
<Exec Command="$(RestoreCommand)"
Condition="'$(OS)' != 'Windows_NT' And Exists('$(PackagesConfig)')" />

<Exec Command="$(RestoreCommand)"
LogStandardErrorAsError="true"
Condition="'$(OS)' == 'Windows_NT' And Exists('$(PackagesConfig)')" />
</Target>

<Target Name="BuildPackage" DependsOnTargets="CheckPrerequisites">
<Exec Command="$(BuildCommand)"
Condition=" '$(OS)' != 'Windows_NT' " />

<Exec Command="$(BuildCommand)"
LogStandardErrorAsError="true"
Condition=" '$(OS)' == 'Windows_NT' " />
</Target>

<UsingTask TaskName="DownloadNuGet" TaskFactory="CodeTaskFactory" AssemblyFile="$(MSBuildToolsPath)\Microsoft.Build.Tasks.v4.0.dll">
<ParameterGroup>
<OutputFilename ParameterType="System.String" Required="true" />
</ParameterGroup>
<Task>
<Reference Include="System.Core" />
<Using Namespace="System" />
<Using Namespace="System.IO" />
<Using Namespace="System.Net" />
<Using Namespace="Microsoft.Build.Framework" />
<Using Namespace="Microsoft.Build.Utilities" />
<Code Type="Fragment" Language="cs">
<![CDATA[
try {
OutputFilename = Path.GetFullPath(OutputFilename);

Log.LogMessage("Downloading latest version of NuGet.exe...");
WebClient webClient = new WebClient();
webClient.DownloadFile("https://www.nuget.org/nuget.exe", OutputFilename);

return true;
}
catch (Exception ex) {
Log.LogErrorFromException(ex);
return false;
}
]]>
</Code>
</Task>
</UsingTask>
</Project>
41 changes: 29 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,25 +1,18 @@
#TeamCitySharp
#TeamCitySharp fork by @borismod

*.NET Library to access TeamCity via their REST API.
* Fork of Paul Slack's original .NET Library to access TeamCity via their REST API. This fork has some additional features, bug fixes and breaking changes. Tested on TeamCity 8.0.5 and 9.1

For more information on TeamCity visit:
http://www.jetbrains.com/teamcity

##Releases
Please find the release notes [here](https://github.com/stack72/TeamCitySharp/releases)
[TeamCity REST API v9](https://confluence.jetbrains.com/display/TCD9/REST+API)

##License
http://stack72.mit-license.org/

##Installation
There are 2 ways to use TeamCitySharp:
Currently there is one way of using TeamCitySharp:

* install-package TeamCitysharp (via Nuget)
* Download source and compile

##Build Monitor
* There is a sample build monitor built with TeamCitySharp. It can be found at [TeamCityMonitor](https://github.com/stack72/TeamCityMonitor)

##Sample Usage
To get a list of projects

Expand Down Expand Up @@ -58,6 +51,7 @@ There are many tasks that the TeamCity API can do for us. TeamCitySharp groups t
* VcsRoots
* Changes
* BuildArtifacts
* TestOccurrences

Each area has its own list of methods available

Expand Down Expand Up @@ -121,6 +115,12 @@ Each area has its own list of methods available
void DeleteAllBuildTypeParameters(BuildTypeLocator locator);
void PutAllBuildTypeParameters(BuildTypeLocator locator, IDictionary<string, string> parameters);
void DownloadConfiguration(BuildTypeLocator locator, Action<string> downloadHandler);

void TriggerBuildConfiguration(string buildConfigId)
void TriggerBuildConfiguration(string buildConfigId, Property[] properties);
void TriggerBuildConfiguration(string buildConfigId, int agentId, Property[] properties)

void UpdateName(BuildtypeLocator buildTypeLocator, string newName);

###ServerInformation
Server ServerInfo();
Expand Down Expand Up @@ -153,10 +153,27 @@ Each area has its own list of methods available
Change ByChangeId(string id);
Change LastChangeDetailByBuildConfigId(string buildConfigId);
List<Change> ByBuildConfigId(string buildConfigId);

// Return list of changes with basic information
List<Change> ByBuildId(long buildId);

/// Returns list of changes with their details
List<Change> ByBuildIdWithDetails(long buildId);

###BuildArtifacts
void DownloadArtifactsByBuildId(string buildId, Action<string> downloadHandler);

###TestOccurrences
List<TestOccurrence> TestOccurrencesByBuildId(long buildId, int? indexStart = 0, int? maxResults = 100);
List<TestOccurrence> FailedTestOccurrencesByBuildId(long buildId, int? indexStart = 0, int? maxResults = 100);

/// Retrieves an instance of TestOccurence by Id as received from TeamCity API
TestOccurrence TestOccurrenceById(string testOccurenceLocator);

###Investigations
List<Investigation> InvestigationsById(string testId);
List<Investigation> InvestigationsByName(string testName);

##Credits

Copyright (c) 2013 Paul Stack (@stack72)
Expand All @@ -169,4 +186,4 @@ Thanks to the following contributors:
* Alexander Fast (@mizipzor)
* Serge Baltic
* Philipp Dolder
* Mark deVilliers
* Mark deVilliers
13 changes: 11 additions & 2 deletions TeamCitySharp.sln
Original file line number Diff line number Diff line change
@@ -1,13 +1,22 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 2012
# Visual Studio 2013
VisualStudioVersion = 12.0.31101.0
MinimumVisualStudioVersion = 10.0.40219.1
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Tests", "Tests", "{263F35DD-20C1-4209-B121-E962C9328C70}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "TeamCitySharp.IntegrationTests", "src\Tests\IntegrationTests\TeamCitySharp.IntegrationTests.csproj", "{BA409A09-CC7B-4A71-A3D4-FE27234A721B}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "TeamCitySharp", "src\TeamCitySharp\TeamCitySharp.csproj", "{87598714-132F-478E-866E-8C1AF3E83057}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "TeamCitySharp.UnitTests", "src\Tests\UnitTests\TeamCitySharp.UnitTests.csproj", "{1DA175C4-2A6F-4B52-A9B4-87D382150AE9}"
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "TeamCitySharp.Tests", "src\Tests\UnitTests\TeamCitySharp.Tests.csproj", "{1DA175C4-2A6F-4B52-A9B4-87D382150AE9}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = ".nuget", ".nuget", "{21AC60B5-105A-41D2-8A42-2CBA14B6D128}"
ProjectSection(SolutionItems) = preProject
.nuget\NuGet.Config = .nuget\NuGet.Config
.nuget\NuGet.exe = .nuget\NuGet.exe
.nuget\NuGet.targets = .nuget\NuGet.targets
EndProjectSection
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Expand Down
Binary file removed packages/EasyHttp.1.6.1.0/EasyHttp.1.6.1.0.nupkg
Binary file not shown.
Binary file removed packages/EasyHttp.1.6.1.0/lib/net40/EasyHttp.dll
Binary file not shown.
Binary file removed packages/EasyHttp.1.6.1.0/lib/sl40-wp/EasyHttp.dll
Binary file not shown.
Binary file removed packages/EasyHttp.1.6.1.0/lib/sl40/EasyHttp.dll
Binary file not shown.
Binary file not shown.
Binary file added packages/EasyHttp.1.6.86.0/lib/net40/EasyHttp.dll
Binary file not shown.
Binary file added packages/EasyHttp.1.6.86.0/lib/net40/EasyHttp.pdb
Binary file not shown.
2 changes: 1 addition & 1 deletion packages/repositories.config
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<repositories>
<repository path="..\src\Samples\TeamCitySharp.BuildMonitor\packages.config" />
<repository path="..\src\TeamCitySharp\packages.config" />
<repository path="..\src\Tests\IntegrationTests\packages.config" />
<repository path="..\src\Tests\UnitTests\packages.config" />
</repositories>
77 changes: 75 additions & 2 deletions src/TeamCitySharp/ActionTypes/BuildConfigs.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Net.Mime;
using System.Text;
using System.Xml;
using EasyHttp.Http;
using TeamCitySharp.Connection;
Expand All @@ -12,9 +14,9 @@ namespace TeamCitySharp.ActionTypes
{
internal class BuildConfigs : IBuildConfigs
{
private readonly TeamCityCaller _caller;
private readonly ITeamCityCaller _caller;

internal BuildConfigs(TeamCityCaller caller)
internal BuildConfigs(ITeamCityCaller caller)
{
_caller = caller;
}
Expand Down Expand Up @@ -85,6 +87,16 @@ public BuildConfig CreateConfiguration(string projectName, string configurationN
return _caller.PostFormat<BuildConfig>(configurationName, HttpContentTypes.TextPlain, HttpContentTypes.ApplicationJson, "/app/rest/projects/name:{0}/buildTypes", projectName);
}

public BuildConfig CreateConfiguration(ProjectLocator projectLocator, string configurationName)
{
return _caller.PostFormat<BuildConfig>(configurationName, HttpContentTypes.TextPlain, HttpContentTypes.ApplicationJson, "/app/rest/projects/{0}/buildTypes", projectLocator);
}

public void AttachToTemplate(BuildTypeLocator buildTypeLocator, string buildTemplateId)
{
_caller.PutFormat(buildTemplateId, HttpContentTypes.TextPlain, "/app/rest/buildTypes/{0}/template", buildTypeLocator);
}

public void SetConfigurationSetting(BuildTypeLocator locator, string settingName, string settingValue)
{
_caller.PutFormat(settingValue, HttpContentTypes.TextPlain, "/app/rest/buildTypes/{0}/settings/{1}", locator, settingName);
Expand Down Expand Up @@ -158,6 +170,62 @@ public void DownloadConfiguration(BuildTypeLocator locator, Action<string> downl
_caller.GetDownloadFormat(downloadHandler, "/app/rest/buildTypes/{0}", locator);
}

public BuildConfig CopyBuildConfiguration(BuildTypeLocator buildTypeLocator, ProjectLocator destinationProjectLocator, string newConfigurationName)
{
var data = string.Format(@"<newBuildTypeDescription name='{0}' sourceBuildTypeLocator='{1}' copyAllAssociatedSettings='true' shareVCSRoots='false'/>", newConfigurationName, buildTypeLocator);

return _caller.PostFormat<BuildConfig>(data, HttpContentTypes.ApplicationXml, HttpContentTypes.ApplicationJson, "/app/rest/projects/{0}/buildTypes", destinationProjectLocator);
}

public void TriggerBuildConfiguration(string buildConfigId)
{
var data = CreateTriggerBody(buildConfigId, null, new Property[0]);

_caller.PostFormat(data, HttpContentTypes.ApplicationXml, "/app/rest/buildQueue");
}

public void TriggerBuildConfiguration(string buildConfigId, Property[] properties)
{
var triggerBody = CreateTriggerBody(buildConfigId, null, properties);

_caller.PostFormat(triggerBody, HttpContentTypes.ApplicationXml, "/app/rest/buildQueue");
}

public void TriggerBuildConfiguration(string buildConfigId, int agentId, Property[] properties)
{
var bodyBuilder = CreateTriggerBody(buildConfigId, agentId, properties);

_caller.PostFormat(bodyBuilder, HttpContentTypes.ApplicationXml, "/app/rest/buildQueue");
}

private static string CreateTriggerBody(string buildConfigId, int? agentId, Property[] properties)
{
var bodyBuilder = new StringBuilder();
bodyBuilder.Append(@"<build>").AppendLine()
.AppendFormat(@"<buildType id=""{0}""/>", buildConfigId).AppendLine();

if (agentId.HasValue)
{
bodyBuilder.AppendFormat(@"<agent id=""{0}""/>", agentId).AppendLine();
}

if (properties.Any())
{
bodyBuilder.Append(@"<properties>").AppendLine();

foreach (var property in properties)
{
bodyBuilder.AppendFormat(@"<property name=""{0}"" value=""{1}""/>", property.Name, property.Value).AppendLine();
}

bodyBuilder.Append(@"</properties>").AppendLine();
}

bodyBuilder.Append("</build>").AppendLine();

return bodyBuilder.ToString();
}

public void PostRawAgentRequirement(BuildTypeLocator locator, string rawXml)
{
_caller.PostFormat(rawXml, HttpContentTypes.ApplicationXml, "/app/rest/buildTypes/{0}/agent-requirements", locator);
Expand Down Expand Up @@ -209,5 +277,10 @@ public BuildConfig BuildType(BuildTypeLocator locator)

return build;
}

public void UpdateName(BuildTypeLocator buildTypeLocator, string newName)
{
_caller.PutFormat(newName, HttpContentTypes.TextPlain, "/app/rest/buildTypes/{0}/name", buildTypeLocator);
}
}
}
Loading