-
-
Notifications
You must be signed in to change notification settings - Fork 740
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add Additional Information to TeamCityBuildInfo #3113
Conversation
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
NOTE: no test of loading the XML files have been added as i am unsure about the rules/convention for this sort of test for cake.
Usually, we add sample XML to resources so we can test functionality works on known good data and keep that working overtime.
One example you can look at is XML peek tests
Resources
cake/src/Cake.Common.Tests/Properties/Resources.Designer.cs
Lines 771 to 775 in ec61403
public static string XmlPeek_Xml_With_Namespace { | |
get { | |
return ResourceManager.GetString("XmlPeek_Xml_With_Namespace", resourceCulture); | |
} | |
} |
cake/src/Cake.Common.Tests/Properties/Resources.resx
Lines 1033 to 1047 in ec61403
<data name="XmlPeek_Xml_With_Namespace" xml:space="preserve"> | |
<value><?xml version="1.0" encoding="utf-8"?> | |
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> | |
<PropertyGroup> | |
<WebPublishMethod>FileSystem</WebPublishMethod> | |
<LastUsedBuildConfiguration>DeploymentTemplate</LastUsedBuildConfiguration> | |
<LastUsedPlatform>Any CPU</LastUsedPlatform> | |
<SiteUrlToLaunchAfterPublish /> | |
<LaunchSiteAfterPublish>True</LaunchSiteAfterPublish> | |
<ExcludeApp_Data>False</ExcludeApp_Data> | |
<publishUrl>C:\Deployment\DeploymentTemplate\WebApi</publishUrl> | |
<DeleteExistingFiles>False</DeleteExistingFiles> | |
</PropertyGroup> | |
</Project></value> | |
</data> |
How it can be accessed/used in tests.
cake/src/Cake.Common.Tests/Unit/XML/XmlPeekAliasesTests.cs
Lines 111 to 124 in 8bc1584
[Fact] | |
public void Should_Get_Element_Value_With_Namespace() | |
{ | |
// Given | |
var fixture = new XmlPeekAliasesFixture(); | |
fixture.SetContent(Properties.Resources.XmlPeek_Xml_With_Namespace); | |
fixture.Settings.Namespaces.Add("msbuild", "http://schemas.microsoft.com/developer/msbuild/2003"); | |
// When | |
var result = fixture.Peek("/msbuild:Project/msbuild:PropertyGroup/msbuild:publishUrl"); | |
// Then | |
Assert.Equal("C:\\Deployment\\DeploymentTemplate\\WebApi", result); | |
} |
Perfect, I shall add a test with some sample data. Thanks for the quick review |
@devlead I have added tests now. This did require me to update some other bits and other tests to support passing the IFileSystem through. |
edac95f
to
c9e0852
Compare
@BlythMeister starting to look good to me 👍 There's a few merge conflicts because older PRs merged, could you please rebase against latest develop branch and take a look at addressing them? Also is there an issue related to this PR? If not could you please add one? Normally we require issues before PR for buying, but we also use them for release notes and blog post generations. |
Ahh sure. I'll rebase on monday and will raise an issue and tag it to this pr in the description 👍 |
Turns out someone had raised an issue...I now raised a duplicate 🤦 |
@BlythMeister @devlead PR LGTM, but wanted to run something by you before it's too late to make changes (if any needed) to the TeamCity currently generates 6 (six) files per build, 3 (three) different pairs / sets or properties ( 1. TeamCity configuration parameters for build
2. TeamCity build properties without 'system.' prefix
3. TeamCity build runner parameters
This PR is implementing number (1) above and exposing the values However, once we implement items (2) and (3), how should we make these properties available? One option could be completely separate properties, e.g. Another option would be to merge all three files into One other option, would be to rename the property in this PR to be something more specific to the file it reads from e.g. What do you think? |
I think renaming the properties makes good sense. I would be happy to include the other files in this PR aswell if you think it would be useful? I am already reading file 2 in order to find the path for file 1, so adding file 3 in and exposing file 2 rather than discarding it is pretty trivial and can implement them all with lazy, so files only read when needed. I'm not working until Monday, but will sort conflicts and and the last file in then 👍 |
Sounds great @BlythMeister. I didn't want to augment the scope of your PR, but since you're offering I'll take it 😄 In terms of the API, I'm fine with 3 separate dictionaries with different names, but let's see if we can get a few more eyes on this PR from the @cake-build/cake-team in case they have other ideas |
As a 1st pr and my 1st use of cake. So far the community have been great. I'm more than happy to give back where I can 🙂 |
0a9adf6
to
9237a25
Compare
@augustoproiete @devlead I have rebased this on develop & resolved the conflicts. |
9237a25
to
bb30a41
Compare
Required adding IFileSystem and then updates to other bits to pull the IFileSystem through
bb30a41
to
0ea85e9
Compare
End-to-end test results running on TeamCity 2020.2.2:
TeamCity generated files
<?xml version="1.0" encoding="utf-8" standalone="no"?>
<!DOCTYPE properties SYSTEM "http://java.sun.com/dtd/properties.dtd">
<properties>
<comment>TeamCity build properties without 'system.' prefix</comment>
<entry key="agent.home.dir">D:\TeamCity\buildAgent01</entry>
<entry key="agent.name">AUGUSTO-TC-01</entry>
<entry key="teamcity.version">2020.2.2 (build 85899)</entry>
</properties> - <?xml version="1.0" encoding="utf-8" standalone="no"?>
<!DOCTYPE properties SYSTEM "http://java.sun.com/dtd/properties.dtd">
<properties>
<comment>TeamCity configuration parameters for build with id 214913</comment>
<entry key="build.triggeredBy">C. Augusto Proiete</entry>
<entry key="build.triggeredBy.username">augustoproiete</entry>
<entry key="DotNetCLI_Path">C:\Program Files\dotnet\dotnet.exe</entry>
</properties>
<?xml version="1.0" encoding="utf-8" standalone="no"?>
<!DOCTYPE properties SYSTEM "http://java.sun.com/dtd/properties.dtd">
<properties>
<comment>TeamCity build runner parameters</comment>
<entry key="teamcity.build.checkoutDir">D:\agent01\w\ad0d02f87a570f9d</entry>
<entry key="teamcity.fail.exit.code">true</entry>
<entry key="teamcity.step.mode">default</entry>
<entry key="use.custom.script">true</entry>
</properties> Test script
Information("TeamCity.Environment.Build.BranchName: {0}", TeamCity.Environment.Build.BranchName);
Information("TeamCity.Environment.Build.VcsBranchName: {0}", TeamCity.Environment.Build.VcsBranchName);
Information("");
Information("---");
Information("");
Information("TeamCity.Environment.Build.BuildProperties:");
foreach (var p in TeamCity.Environment.Build.BuildProperties)
{
Information(" - {0}={1}", p.Key, p.Value);
}
Information("");
Information("---");
Information("");
Information("TeamCity.Environment.Build.ConfigProperties:");
foreach (var p in TeamCity.Environment.Build.ConfigProperties)
{
Information(" - {0}={1}", p.Key, p.Value);
}
Information("");
Information("---");
Information("");
Information("TeamCity.Environment.Build.RunnerProperties:");
foreach (var p in TeamCity.Environment.Build.RunnerProperties)
{
Information(" - {0}={1}", p.Key, p.Value);
} Build log:
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM!
@BlythMeister your changes have been merged, thanks for your contribution 👍 |
Adding support in the
TeamCityBuildInfo
to load the properties XML files as a key/value data store.Files loaded as a Lazy to prevent IO when properties are not required & to also then cache the results if subsequent queries are to properties are required.
Also exposing the teamcity branch name.
NOTE: no test of loading the XML files have been added as i am unsure about the rules/convention for this sort of test for cake.
Fixes #2967