Artifact dependency from the same build configuration in TeamCity - build

I'd like to setup a TeamCity build that will perform an incremental build.
For this, i want to store the build outputs (.dll files) as artifacts, and reuse them on every subsequent build (copy the latest artifacts to the build agent before starting the build).
This will effectively place the last build's artifacts in the project's output folder, so MSBuild could use those artifacts to determine whether it needs to rebuild anything from sources.
I've tried to do this, but it seems TeamCity doesn't allow configuring artifact dependencies from the same build configuration.
For example, if i have a "Build Plugins" configuration that generates a collection of plugin DLLs, i cannot use these as a dependency for the same build configuration...
Is there any inherent way to overcome this in TeamCity, or to create an easy solution myself?

It appears it is only possible to do this when using templates.
You can create a template for a build. Then you create a build from that template. After that you add this build to the artefact dependencies from the template. This allows for circular dependencies.
I have found no other way.

It looks like you can do this now! It seems to work in 9.0.1, and TW-12984 says it should work as far back as 8.1.

Related

TeamCity c++ gradle build deletes artifact dependencies

I'm new to TeamCity, migrating from a different CI product, and trying to figure out how to configure a working build for a c++ project on version 9.1.6 of TeamCity.
The problem I'm having is that the agent is deleting my dependency directories right before (or during) the component build, and I can't find a record of why this is happening anywhere in the build log.
The build layout for any component in the system looks like so:
<base-dir>
|
+---<to-be-built>
+---<dependency-1>
+---Include
+---Lib
+---<dependency-2>
+---Include
+---Lib
...so, whatever the checkoutDir is for the component, it is assumed that all dependencies will be found in peer directories, named after the dependency, with no version information in the folder name.
For example, if version 3.0.2 of "MyExe" depends on version 1.1.0 of "SomeLibA" and version 2.1.0 of "SomeLibB", the file system should look like so:
MyExe_3.0.2
|
+---MyExe
+---SomeLibA
+---Include
+---Lib
+---SomeLibB
+---Include
+---Lib
So, to create this build layout, the build configuration for version 3.0.2 of "MyExe" has specified a custom checkout directory like so: "MyExe_3.0.2/MyExe".
So far, so good. The dependencies are configured as artifact dependencies and their destination directory is specified as '../'. This also seems straightforward.
When I kick off the build, though, I see the to-be-built component being retrieved, then I see the dependencies arrive, and then the gradle task I've configured for the build runs, and right at that moment, or just before, all of the dependency directories (SomeLibA and SomeLibB) get wiped out, and of course the component can't find any of its dependencies' include files and compilation fails.
I've turned off 'Clean all files in the checkout directory' on the component and 'Clean destination paths before downloading artifacts' on all dependencies, but this has no effect.
I've only found 2 hints possibly related to this behavior, but I'm not sure why either of them would be causing this problem.
The first is a little warning symbol on the Version Control Settings tab for "MyExe" which says "This directory might be cleaned by TeamCity before the build", referring to the custom directory. But, the directory that's getting cleaned out during the build run is not the checkout directory, it's the checkout directory's parent directory.
The only other possible candidate I can find is that the gradle task I've configured isn't the only task specified when the build runs. Instead of seeing "gradlew.bat myGradleTask" in the build log, I'm seeing "gradlew.bat --init-script C:\TeamCity\BuildAgent\plugins\gradle-runner\scripts\init.gradle myGradleTask".
But, I've looked through that init script, and didn't see anything related to directory cleanup.
I'm stumped. Does anyone have an idea what is going on, and how to work around it so this build can complete successfully? Acceptable solutions have to preserve the build layout requirements above.
The problem here was in disabling "Clean all files in the checkout directory before the build".
Disabling this checkbox has the effect of wiping out the contents of the entire path to the checkout directory.
For reference, see documentation here:
https://confluence.jetbrains.com/display/TCD9/Clean+Checkout
...from which the relevant excerpt is:
Automatic Clean Checkout
If clean checkout is not enabled, TeamCity updates the sources in the
checkout directory incrementally to the required state. TeamCity tries
to detect if the sources in the checkout directory are not
corresponding to the expected state and triggers clean checkout in
such cases to ensure sources are appropriate.
This means that under certain circumstances TeamCity can detect clean
checkout is necessary even if it is not enabled in the VCS settings
and not requested by the user from web UI. In such cases all the
content of the checkout directory is deleted and it is re-populated by
the sources from scratch. If any details are available on the
decision, they are added into the build log before checkout-related
logging.
Enabling this checkbox had the effect of leaving the dependency directories in place.

MSBuild unnecessarily runs custombuild tool when run for different configurations

I have a C++ project for which I need to run a custom build tool on some header files to generate code that is required when compiling this project. In general my configuration works. I trigger a build, VS/MSBuild detects whether the output files are up-to-date and runs the custom build tool only if necessary.
However, a problem arises if the build is run in combination with another configuration of the same project. Both configurations depend on the output files of the custom build tool. So if run sequentially only one configuration should trigger the custom build tool to run. For which ever configuration a build is triggered second the output files of the custom build tool are already present and up-to-date. So there is no need to build them again. Unfortunately this is exactly what is happening. Since the custom build tool takes quite some time to run, this increases build times dramatically.
Another interesting aspect is, that once both configuration have run, I can trigger any of them again and the custom build tool is not invoked.
What I would have expected from the documentation is that the custom build tool is triggered:
If any of the files specified as Outputs is missing
If the file for which I specified the custom build tool was modified later than any of the existing files specified as Outputs
If any of the files I specified as Additional Dependencies were modified later than any of the existing files specified as Outputs
But all of this independent from the configuration for which the build was triggered.
Does anyone have an idea on why this might happen? I checked that the settings for the custom build tool are identical for both configurations. The output files are generated into the same folder for both configurations.
The documentation you're referring to is basically correct but it omits to say that everything in there is basically per project configuration/platform because it uses tracker.exe which depends on .tlog files which by default go into the intermediate directory. So as you figured out, making all configurations use the same location for the tlog files should keep the tracker happy and only invoke the custom build tool when needed, independent of configuration/platform. I'm not sure I'd recommend any of this though, sharing temporary object files might cause you problems later.
Another way to deal with this is adding a seperate project with just one configuration, say 'Custom', and do the custom build there. Than make your current project(s) depend on that project and in the solution's Configuration Manager adjust all entries so each configuration you have now builds the 'Custom' configuration for the new project.

Export projects as .jar in IntelliJ

I've recently switched from Eclipse to IntelliJ, and i'm a bit confused as to how to export projects as .jars. I've seen other posts, where the answer is to go to File > Project Structure > Artifacts, and add a new build artifact, and then use Build > Build Artifacts. However, I don't know where the jar is being saved, (if it is) and I would also like to know how to make it export to a custom location. I also think it's kind of strange how it takes IntelliJ around 20 or so seconds to compile the jar, while in Eclipse it only takes half a second.
You can also use "Build on make" option. IntelliJ will make new jar for you on each "make" invocation. Assuming there were changes. Otherwise it will keep the existing jar.
Also, "Artifacts" configuration screen contains the location of the artifact.

Is it possible to skip buildSrc project in a multi-module Gradle build?

We are in the early stage of migrating from a complex Maven build system to hopefully a simpler Gradle build system. Unfortunately I put some of our own custom Maven plugin extensions into /buildSrc.
Is it possible to skip the internal buildSrc project with Gradle? I'd rather not build what's in this directory at this time.
Eventually it would be replaced with our own custom Gradle plugins but for now I would ideally want to skip this project entirely.
buildSrc will get built as soon as the directory exists. So the best way is to delete or rename that directory.
Another option would be to add a buildSrc/build.gradle containing tasks.all { enabled = false }. Not quite the same as skipping the project entirely, though.

Create Visual Studio "Custom Build Step" with CMake

I would like to run a code generator every time my project is built in Visual Studio, even if no source file in the project was changed. Therefore I would like to have a custom build step set up as explained in Visual Studio: Run C++ project Post-Build Event even if project is up-to-date.
How can I create such a build step with CMake?
I think a custom target is what you are looking for: add_custom_target
From the documentation:
Add a target with no output so it will always be built.
Or if you are generating a code file,
https://cmake.org/cmake/help/v2.8.8/cmake.html#command:add_custom_target
can be run POST_BUILD and generate output.
This is afaik not possible with CMake, and is therefore a missing feature for sure.
The answer from Tarydon in the question you refer to, is about setting up precisely what you want - a "Custom Build Step". This means that you still only have your main target (VS Project), with something that looks like a "Post-Build Event" but technically isn't, since Post-Build Events aren't run if the project is up-to-date.
The answer from tpg2114 works, but has one major drawback; it spams your solution with phony projects. In case you have a hundred projects in a solution, having to add another hundred just as post-build wrappers to the first hundred is of course undesirable.
Depending on your situation, it might sometimes be easier to use Post-Build Events and force a rebuild of at least one source file, for the project to actually build and therefore also run your custom command.