How do I disable Teamcity deploying artifacts for personal builds? - intellij-idea

I am using Teamcity 9.0.2 and IntelliJ 14.1.5. I have a Teamcity build with a maven step configured with "Deploy Maven artifacts" enabled.
When I run a personal build, the artifacts get deployed to artifactory.
How do I disable deploying artifacts for personal builds by default for each of my builds?

Currently it's not possible to execute build steps based on condition. Vote for the related request: https://youtrack.jetbrains.com/issue/TW-17939.
As of now you can:
Create a separate build configuration without Deploy build step (recommended). You can use templates to simplify the setup. In this case it will be easier to interpret the results and the statistics of the builds will be informative.
If build is personal %system.build.is.personal% parameter is set to true. So you can check a condition in the build step and skip it if needed.

This is the workaround i found to this issue. I created two additional build steps, The first labeled "Check for Personal Build" is a Nant step that validation against the BUILD_IS_PERSONAL environmental variable, and if set, updates a teamcity env.PublishPath variable.
<project name="UpdateForPersonal" default="default">
<target name="default">
<if test="${environment::variable-exists('BUILD_IS_PERSONAL')}">
<echo message="##teamcity[setParameter name='env.PublishPath' value='fake']" />
</if>
</target>
</project>
The second step is a simple CMD the writes as dummy "Publish" message to the logs, but the "Custom published artifacts" values is from the "Deploy Artifacts To Artifactory" section padded by %env.PublishPath%.
If the build is personal, the publish to artifactory will not find any files and log warnings into the logs, but the build passes and no artifacts are published.
The value of %env.PublishPath% is set to "" by default in the configuration build.

Related

How to have different Teamcity VSBuild Configurations (Debug/Release) for each specific branch?

I have a build configuration that does my building and unit testing for all of my branches of my project. I have another configuration that does my deploying. I need the first configuration to do the build with a "Debug" target if its against a "development" environment and a "Release" target against the rest. Is there a way to go about this without having to make different build configurations?
For all the builds I manage here at my job, we always create different build configurations in TeamCity for Debug and Release. I don't know more about your build environment so obviously I can't answer specifically.
You can however reduce almost all the duplication by using templates. Which is nice. Then the only unique information in your debug build is the word 'Debug', and same for your 'Release' build.

TeamCity Build Failure

I have tried many things today to get my build to work in Teamcity but to no avail.
Here is my setup.
I have 2 build configurations in TeamCity
Build Solution
Build Deployment Package Debug
Build Solution is triggered by an SVN checkin and builds the solution file. This configuration works fine.
Build Deployment Package Debug has Build Solution as its dependency and has two (MSBuild) build steps. The solution contains two websites: a front end one and an admin one. One build step builds the front end site and the other the admin site. The end result is that it puts the combined results into a zip file for deployment to the deployment server (I've not got to this bit yet).
The problem that I have is that the Build Deployment Package Debug configuration fails trying to build the first site. This is the error:
[18:40:25]Step 1/2: Web (MSBuild) (29s)
[18:40:28][Step 1/2] x.Web\x.Web.csproj.teamcity: Build target: Build (27s)
[18:40:50][x.Web\x.Web.csproj.teamcity] MvcBuildViews (4s)
[18:40:50][MvcBuildViews] AspNetCompiler (4s)
[18:40:55][AspNetCompiler] C:\BuildAgent\work\252ec59002ecc2d\x.Web\obj\debug\csautoparameterize\original\web.config(39, 0): error ASPCONFIG: It is an error to use a section registered as allowDefinition='MachineToApplication' beyond application level. This error can be caused by a virtual directory not being configured as an application in IIS.
[18:40:55][x.Web\x.Web.csproj.teamcity] Project x.Web\x.Web.csproj.teamcity failed.
[18:40:55][Step 1/2] Step Web (MSBuild) failed
Here are Build Paramters -> System Properties
Name Value
system._PackageTempDir c:\deploypackage
system.Configuration Debug
system.CreatePackageOnPublish True
system.DeployIisAppPath Debug
system.DeployOnBuild True
system.PackageLocation c:\buildshares\Debug\Debug.zip
Here's what I did to solve this
I already had this in my project file
<Target Name="MvcBuildViews" AfterTargets="AfterBuild" Condition="'$(MvcBuildViews)'=='true'">
<AspNetCompiler VirtualPath="temp" PhysicalPath="$(WebProjectOutputDir)" />
</Target>
But I needed to add this also
<Target Name="AfterBuild">
<RemoveDir Directories="$(BaseIntermediateOutputPath)" />
</Target>
Doing this fixed the issue.
I hope this helps someone else who is working on TeamCity in the future.

Deploy a specific revison based on pinned build using MSBuild in TeamCity

My setup in TeamCity:
I've got a "CI configuration" running a singular build step that uses a MSBuild script checked-in to the from the project. The configuration has a number of sub targets such as unit tests, deployment to test site etc.
I also have a "Deploy configuration" with a singular target using another MSBuild script that only does deployment (using msdeploy). This is triggered manually.
My problem:
The "Deploy configuration" need to deploy a revision based on the latest pinned build from "CI configuration". The whole idea is essentially to get a one-click-deployment functionality based on latest pinned build in CI. Does anyone know how to do this in MSBuild using TeamCity?
Im guessing I need to use "Snapshot Dependencies" to get the latest pinned revision, but I have not been able to figure out how to deploy that snapshop in the MSBuild script.
Also I'd like to specify that I would like to do this within MSBuild script and not by using the "Custom build" dialog in TeamCity.
Ok, figured it out on my own.
You need to set a row in the "Artifacts path" like so "*/ => source" in the CI configuration.
Then add a "Artifact dependency" in the Deploy configuration pointing to the CI configuration in the "Depend on" select and set "Get artifacts from" to "Last pinned build" and then point to the "Artifact rules" like so: "source => source".
And at last, inside my MSBuild file, I added "/source/", to my project path in the Target-node with the deploy.
Works like a sharm every deployment. :-)

Why Unpublishable?

We have a solution that contains 17 projects.
Solution has several configurations such as Debug, Release, Test, Publish and etc.
Also team project has several build definitions, each one is specialized for a configuration.
We use Release configuration build for nightly builds and Publish configuration build for publish and deployment.
So these build definitions, build same source code. But there is a problem...
Our nightly build creates obj\Release directories for each project but publish build doesn't.
Because of this publish build doesn't create server publish package.
When I looked to the build logs I saw the differences like below.
Nightly build - Release configuration (for each project)
PrepareForBuild:
Creating directory "obj\Release\".
Publish build - Publish configuration (for each project)
_DeploymentUnpublishable:
Skipping unpublishable project.
But I couldn't understand why?
Which flag controls this?
We are using TFS 2010, so Team Build 2010.
Try adding the following deployment settings to the project file inside the property group for the build configuration you want to publish:
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
...
<FilesToIncludeForPublish>OnlyFilesToRunTheApp</FilesToIncludeForPublish>
<DeployOnBuild>true</DeployOnBuild>
<DeployTarget>Package</DeployTarget>
<PackageAsSingleFile>true</PackageAsSingleFile>
</PropertyGroup>
I was getting a similar error on a web project's CI build. Adding the deployment settings to the web.csproj file corrected it.

Configure a hudson maven job to keep building if there are test failures, but only deploy if there are no test failures

I've created a hudson job for our maven multi-project with 5 modules to deploy the SNAPSHOT artifacts to the maven repository. That's ok, as long as it builds successfully without test failures. However, now I'd like to fulfill the following requirements:
When a module has a test failure, the build should continue bulding and test the other modules, but turn yellow. Using -Dmaven.test.failure.ignore=true accomplishes, but fails at the next requirement.
When a module has a test failure, none of the artifacts should be deployed to the maven repository. Other projects depend on the snapshots this project and those projects only want to use the latest snapshots that don't have any failing tests.
Preferably, use the hudson maven integration instead of a free script we get the hudson report pages (red/yellow/blue status per module, build log error coloring, ...). Specifically running the maven build twice (first mvn test -Dmaven.test.failure.ignore=true, than mvn deploy -DskipTests) is not a solution because it's a performance loss and it confuses the hudson report pages and it's not atomic (it updates from the repositories again in the second build).
Is there any way to accomplish this?
There is an post build option called Deploy artifacts to Maven repository. If you do not select Deploy even if the build is unstable, then that mean if test fails, it won't deploy anything. Together with the -fae in the command, thing should work in your desired way
maybe you can try use mvn -fae option with you jobs on hudson - it make maven fail only after full build
If build time isn't a problem for you, I think the better option is to create another job, just for deploying. Something like this:
Configure your original job (let's call it "build job") with "mvn -fae clean install"
Create a new job ("deploy job") with "mvn deploy", and don't configure any Build triggers for it
In the "build job", enable the Build other projects option, under Post-build actions and set it to run your "deploy job".
Maybe you can try to configure both jobs to use the same workspace, saving some time on the whole build/deploy process.
If you happen to use Artifactory as a repository manager, you can use the Hudson/Jenkins Artifactory plugin to deploy your artifacts. This plugin will only deploy your artifacts if all tests pass for all modules of a Maven build.