Skip to content
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 example of how to use Cake with TeamCity #117

Closed
patriksvensson opened this issue Nov 6, 2014 · 32 comments
Closed

Add example of how to use Cake with TeamCity #117

patriksvensson opened this issue Nov 6, 2014 · 32 comments

Comments

@patriksvensson
Copy link
Member

No description provided.

@RichiCoder1
Copy link
Contributor

I may contribute to this issue, since I'm now using cake w/ teamcity at work. What particularly were you interested in documenting? Just running a cake script? Or TC <-> cake interactions?

@johnxjcheng
Copy link

I am very interested in this feature. If someone can provide a simple, step-by-step document to show how to integrate cake with TC, that will be very helpful.

@gep13
Copy link
Member

gep13 commented Nov 29, 2015

@johnxjcheng is there something specific that you are looking for help on?

@johnxjcheng
Copy link

Nothing specific. Just something in general. I am not a TC person. I am more a developer and would like to run build from shell. However many companies have SCM teams that take care of building processes. I just want to make sure if I choose to use CAKE, me or someone else can easily integrate it with TC. Hopefully the TC experts may find that’s easy.

@devlead
Copy link
Member

devlead commented Nov 30, 2015

@johnxjcheng we have now applied for a OSS license for TeamCity, when we get that we can setup and document Cake building under that.

@dbertram
Copy link
Contributor

dbertram commented Mar 8, 2016

One thing we've done with our TeamCity build server is to incorporate TeamCity's custom MSBuild logger into our Cake script. This way MSBuild errors/warnings are surfaced correctly in the TeamCity dashboard/build log UI.

We did this by adding a MSBuildLogger parameter to our build.ps1:

Param(
    ...
    [string]$MSBuildLogger = "",
    ...
)

that's then forwarded to and parsed by build.cake:

var msBuildLogger = Argument<string>("msBuildLogger");

and used by our MSBuild task wrapper:

private void MSBuildTarget(string solution, string configuration, string target)
{
    MSBuild(solution, settings => {
        settings
            .WithTarget(target)
            .SetConfiguration(configuration);

        if (!string.IsNullOrEmpty(msBuildLogger))
        {
            Information("Using custom MSBuild logger: {0}", msBuildLogger);
            settings.ArgumentCustomization = arguments =>
                arguments.Append(string.Format("/logger:{0}", msBuildLogger));
        }
    });
}

And in our TeamCity build config we pass in the appropriate TeamCity system parameters as a script argument to build.ps1:

-MSBuildLogger "JetBrains.BuildServer.MSBuildLoggers.MSBuildLogger,%teamcity.dotnet.msbuild.extensions4.0%"

Ideally the above could be simplified via #473 and/or #702 and possibly by extending ITeamCityProvider to expose something like a GetMSBuildLoggerArgument() method.

@bjorkstromm
Copy link
Member

Here's one happy Cake-TeamCity user that might be able to help if you have any questions.

@johnxjcheng
Copy link

Thanks, our SCM guys integrated cake with teamcity without any difficulty.

Sent from Outlook Mobile

On Mon, Mar 14, 2016 at 1:11 PM -0700, "Martin Björkström" notifications@github.com wrote:

Here's one happy Cake-TeamCity user that might be able to help if you have any questions.


Reply to this email directly or view it on GitHub:
#117 (comment)

@nengberg
Copy link

nengberg commented Jul 8, 2016

Hi,

I'm using Cake with TeamCity as well. What have worked out for me is to execute the .ps1 file from a step with the Powershell runner. The output from the build gets nicely outputted in the build log and if any error occurs in the exeuction the build is aborted.

/Niklas

@wwwlicious
Copy link
Contributor

We do similar and we are using our own fork of cake hosted on an internal feed as cake doesn't play well with corporate proxy environments. Our metarunner is here if this helps anyone

@gep13
Copy link
Member

gep13 commented Jul 11, 2016

@wwwlicious very interesting! I have started implementing a supported TeamCity Meta Runner here:

https://github.com/gep13/cake-teamcity

This will eventually make it into the cake org. Would welcome any feedback that you might have.

Also, why the need to fork Cake? What changes have you had to make? It is something that we should support better in Cake?

@wwwlicious
Copy link
Contributor

@gep13 Cool, will keep tabs on the runner's progress, I would recommend submitting a PR for it to the JetBrains MetaRunner Powerpack repo if you haven't already considered this.

the reason for the fork I mentioned above is the support around not having internet access on the build servers and therefore the need to grab all resources from internal nuget feeds or repo's.

I have a couple of PR's pending (just need to find time to rebase them!) that help with the pre-processor directives and solution package restores but you also need a custom bootstrapper for getting packages.config and nuget.exe from non-internet sources. This was partly the reason for creating a custom metarunner and bootstrapper as mine has alternative paths for these, so I don't have to repeat the customisations again and again for each repo.

I'd suggest if you try running cake without internet and cached packages, you'll begin to see why I forked it for yourself. :)

@gep13
Copy link
Member

gep13 commented Jul 12, 2016

@wwwlicious I have thought about submitting to the meta runner power pack repo. That is what we did with the GitVersion Meta Runner, however, I think in this case, we would like to "own" the meta runner, and keep it under direct control of the Cake Team, so that if any changes are required, they can be applied immediatley, and not have to wait the time for a PR into that repo to be accepted.

@wwwlicious said...
the reason for the fork I mentioned above is the support around not having internet access on the build servers and therefore the need to grab all resources from internal nuget feeds or repo's.

The recent talk that I did at NDC Oslo was done completely offline, with no internet connection. The new settings that were exposed via the config file were enough to allow me to get everything working:

http://cakebuild.net/docs/fundamentals/default-configuration-values

If there are more things that you need exposed in order to get this to work then we need to hear about them, as this is definitely a scenario that we would like to support.

The custom bootstrapper would still be required though. however, this is intended to be "your" bootstrapper. The one that comes from Cakebuild.net, is really just a reference sample.

Yip, I ran into the same issues as you, and that was really where the configuration options came from 😄

@wwwlicious
Copy link
Contributor

The main issue for me is that you end up having to modify your machine or user level nuget.config file to set the default system sources or rely on package caching, that's what one of my PR's avoid as I think that isn't acceptable to have to custom configure build agent servers.

Agree completely about the bootstrapper, it was easiest to just host it, along with our custom packages.config and cake.config files on an internal repo for DRY.

Not sure how to reduce friction in this area but perhaps providing override params for bootstrapper paths for nuget.exe, roslyn and nuget sources when installing the bootstrapper script in VS Code.

Hit a few snags in lack of support for output params for MSBuild due to it being parsed from Console.Out rather than executed directly against MSBuild dll's, reverting changes to assemblyinfo files after gitversion tasks to avoid erroneous/accidental commit churn and limited support for Octopus Deploy ops beyond push (which we have another PR in for I think) but nothing that you cannot work around.

Have to say overall, cake is pretty great and way, way faster to get comprehensive build scripts written than my previous adventures in MSBuild, Psake and Teamcity (using steps, custom runners and plugins) so if I sound like I'm moaning, I am ;) ... but it is with ❤️

@gep13
Copy link
Member

gep13 commented Jul 12, 2016

@wwwlicious said...
The main issue for me is that you end up having to modify your machine or user level nuget.config file to set the default system sources or rely on package caching, that's what one of my PR's avoid as I think that isn't acceptable to have to custom configure build agent servers.

So, just to confirm, you didn't want to do something like this:

#tool nuget:http://localhost:8081/repository/cake/?package=xunit.runner.console

Or are you "solely" using the packages.config file for Tool resolution?

@wwwlicious said...
Not sure how to reduce friction in this area but perhaps providing override params for bootstrapper paths for nuget.exe, roslyn and nuget sources when installing the bootstrapper script in VS Code.

Within VSCode, you can configure the download URL for the bootstapper file that you use:

image

That is what I was doing during my demos, so that when you do this:

image

The bootstrapper is the one that you have hosted "somewhere". Would that help with your scenario?

@wwwlicious said...
Have to say overall, cake is pretty great and way, way faster to get comprehensive build scripts written than my previous adventures in MSBuild, Psake and Teamcity (using steps, custom runners and plugins) so if I sound like I'm moaning, I am ;) ... but it is with ❤️

Glad to hear it!!

@wwwlicious
Copy link
Contributor

So, just to confirm, you didn't want to do something like this:

#tool nuget:http://localhost:8081/repository/cake/?package=xunit.runner.console

Or are you "solely" using the packages.config file for Tool resolution?

Correct, standard build script across a bunch of repo's has the following and having switched internal nuget feed addresses a couple of times over the years, I don't like hardcoding these things too often.

//////////////////////////////////////////////////////////////////////
// EXTERNAL NUGET TOOLS
//////////////////////////////////////////////////////////////////////

#tool "xunit.runner.console"
#tool "GitVersion.CommandLine"
#tool "JetBrains.ReSharper.CommandLineTools&prerelease"
#tool "JetBrains.dotCover.CommandLineTools"
#tool "OctopusTools"

//////////////////////////////////////////////////////////////////////
// EXTERNAL NUGET LIBRARIES
//////////////////////////////////////////////////////////////////////

#addin "Cake.StyleCop"
#addin "Cake.Git"

Within VSCode, you can configure the download URL for the bootstapper file that you use:

That's a little gem right there! Yes it would help 👍

@gep13
Copy link
Member

gep13 commented Jul 12, 2016

@wwwlicious gotcha. Just wanted to check that we were on the same page, and sounds like we are.

👍 on using GitVersion! 😄

@devlead
Copy link
Member

devlead commented Jul 12, 2016

Wonder if something like possibility to expand environment vars would help or confuse, something like

#tool nuget:%TOOL_NUGET_FEED_URL%?package=xunit.runner.console

most build servers have the possibility to set environment variables shared upon build agents, would also be easy to set conditionally in bootstrapper scripts (i.e. check subnet or similar).
And could easily be set to alternative feed on devs machine i.e.

@wwwlicious
Copy link
Contributor

wwwlicious commented Jul 12, 2016

Sounds like a reasonable option and would avoid commiting paths to a repo which is useful.

Creates two different methods of env var evaluation though, one usingEnvironmentVariable("foo") and the other inlining syntax %foo% specifically for preprocessor directives . Not sure if this would end up confusing things.

[Edit] Should add that having an environment variable override in the bootstrapper for nuget.exe, roslyn and packages.config locations would be 👍

@gep13
Copy link
Member

gep13 commented Jul 12, 2016

@devlead hmm, not sure if I like that idea, but willing to be convinced.

@wwwlicious
Copy link
Contributor

@wwwlicious very interesting! I have started implementing a supported TeamCity Meta Runner here:

https://github.com/gep13/cake-teamcity

This will eventually make it into the cake org. Would welcome any feedback that you might have

One suggestion is to utilise the teamcity built-in nuget.exe, you can see an example of this in use on my metarunner for xunit where I get both nuget.exe and the xunit runner package from sources configurable per build.

https://github.com/JetBrains/meta-runner-power-pack/blob/master/xUnit.net-dotCover/MRPP_xunit_dotcover.xml#L7

@gep13
Copy link
Member

gep13 commented Jul 12, 2016

@wwwlicious ooo, that sounds like a good idea! Any chance you can add that as an issue on that repo, so that I don't forget about it?

@dtatcox
Copy link

dtatcox commented Feb 27, 2017

@tafs7
Copy link

tafs7 commented Apr 3, 2017

for those of you on this thread that have stated they currently use Team City and Cake, answer me this: did you have a install an edition of the Visual Studio IDE, in order to succesfully execute MSBuild on a solution which has one of the following project types: Web, Data (SqlProj)?

Everywhere on the web that i look I am seeing people say that is the way to go, but I find it hard to believe that in 2017, I'm needing to install the full IDE on my build server. Please tell me there's another way, which does NOT involve manually copying a folder from my dev box to the build server so MSBuild via Cake can find the targets files.

@bjorkstromm
Copy link
Member

@tafs7 I usually never install full IDE on my build agents, it's often sufficient with the Build Tools (e.g. for VS 2015 I use Microsoft Build Tools 2015)

For VS 2017, they seem to have renamed it a bit. Try grabbing "Build Tools for Visual Studio 2017 from here. Select "Other Tools and Frameworks" and "Build Tools for Visual Studio 2017". Additionally for building .SqlProj projects, you might need to reference NuGet package Microsoft.Data.Tools.Msbuild in your solution. You can read about that here

@tafs7
Copy link

tafs7 commented Apr 3, 2017

@mholo65 I've installed both the Microsoft Build Tools 2015 and the Build Tools for VS 2017 on my build agent box, neither of which worked. MSBuild fails when trying to load a target file:
error MSB4019: The imported project "C:\Program Files (x86)\MSBuild\Microsoft\VisualStudio\v14.0\WebApplications\Microsoft.WebApplication.targets" was not found

Even after installing both of above mentioned build tools, that path does not exist on my server.

@wwwlicious
Copy link
Contributor

wwwlicious commented Apr 3, 2017

@tafs7 I normally add this package as a dependency of my web projects, it solves this problem - https://www.nuget.org/packages/MSBuild.Microsoft.VisualStudio.Web.targets

Definitely frustrating though so I sympathise. Installing the IDE though is never the solution, "the web" is wrong! ;)

@yakimovim
Copy link

I wrote a short article describing some simple aspects of integration between Cake and TeamCity:

https://www.codeproject.com/Tips/1271037/Integration-of-Cake-build-script-with-TeamCity

Hope it will be of some help.

@gep13
Copy link
Member

gep13 commented Dec 11, 2018

@yakimovim thanks for doing that.

Could I get you to do a PR into this page:

https://github.com/cake-build/website/blob/develop/input/docs/resources/blogs.md

So that people will be able to find this here as well? Thanks

@yakimovim
Copy link

@gep13 I have created a pull request.

@johnxjcheng
Copy link

johnxjcheng commented Dec 11, 2018 via email

@pascalberger
Copy link
Member

Closing this, as it is a documentation issue which is tracked by cake-build/website#1047

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests