Finish Build trigger does not fire for feature branch - teamcity

I have a TeamCity project configured with 2 build configurations 'A' and 'B'. The 'A' configuration is meant to run against a feature branch and build the solution. It also publishes packages to the team city nuget feed.
I am also using the Octopus Deploy teamcity plugin to automate the creation of releases and deployments in our Octo server. Any packages published by a build configuration to the TeamCity nuget feed are not available to any build steps within the same build configuration so a second build configuration must be created to consume the packages.
As a result the 'B' build configuration is the Octo deployment step and it has a snapshot dependency to build A and an artifact dependency to build A. The artifact dependency has 'Get artifacts from' set to 'Build from the same chain'.
The build chain runs without issues when run with the teamcity vcs default branch. However the 'B' build config does not trigger when the 'A' build config runs against a feature branch. When looking at the build chain in teamcity when a build occurs on a feature branch the 'B' build config says 'Not Triggered'.
I can't find any clear solution to this problem and whether or not this is actually supported by TeamCity. It sounds like in earlier versions of TeamCity (~v7) this was not supported but that the introduction of snapshot/artifact dependencies solved the issue.

Related

Jenkins Maven Integration Plugin building all existing branches

We are using Jenkins with multi-branch pipelines and the Maven Integration plugin. I configured the multi-branch pipeline to "Build whenever a SNAPSHOT dependency is built". When our dev branch was built, it seemed to build every branch of all dependent repos. How may we limit it to only build branch X when branch X is built?

Running of team city build in the loop

I have build configuration in TeamCity with automated tests. I want to run this build configuration in the loop: when one build was finished, new build is started. I can not configure 'Finish Build Trigger', because it is necessary to create snapshot dependencies for it, but I want to run tests for the latest version of code each time. How I can configure such loop?
From your question:
I can not configure 'Finish Build Trigger', because it is necessary to
create snapshot dependencies for it
Actually, it is NOT nescesary to have a snapshot dependency for a "Finish Build Trigger". You will, however, get a warning saying that "There is not snapshot dependency on the selected build configuration", but that will not keep you from triggering on a selected build.
From Teamcity Documentation:
If there is no snapshot dependency, the following limitations exist:
it is likely that a build of the build configuration being triggered will not have the same revisions as the finished build
even if both configurations have the same VCS settings
if a build configuration with the Finish Build Trigger has an artifact dependency on the last finished build of the build
configuration specified in the trigger settings, there is no
guarantee that artifacts of a build which caused build triggering
will be used, because, while the triggered build sits in the build
queue, another build may finish
the build triggered by the Finish Build Trigger will always be triggered in the default branch even if the finished build has some
other branch
I do recommend to select the "Trigger after successful build only" checkbox since you are running unit tests.

Releasing from Nexus staging repository via Jenkins/Maven

I have a Java project. Some parts are jar files, some are war files. I also have Jenkins and Nexus Pro, whereby when a developer on the team commits to SVN, the Jenkins build automatically kicks off.
Using the Maven versions plugin, I am able to mvn versions:set -DnewVersion=1.0.$SVN_REVISION as a pre-build step, and then mvn clean test deploy. At the end of this process, I've got a my-artifact-1.0.1234.jar uploaded to my Nexus Pro Staging Repository.
Since we're working in a CI-type of environment, we might have a hundred (or more) staging builds. When the time is right, the QA team wants to promote a certain build to a "later" environment (think QA, or SIT, or whatever. Environments are more of a locked-down state here.)
The workflow that I want to have happen is this:
Someone decides that Build 1.0.1357 should be Promoted to QA
They go into Jenkins, go to the "Promote to QA" job
They're presented with a list of all possible builds in the Nexus Staging Repository in a drop-down. They select one, and click the "Run" button.
That artifact is "released" from Nexus Staging to Nexus Releases, and further deployed to the QA environment. (I'm not as concerned about the "and deployed to QA" part -- I know how to do that already. It's included here for completeness-of-my-story sake.)
I already know that I can do this from the command-line, and it's working:
mvn nexus-staging:rc-list -DserverId=nexus -DnexusUrl=http://my.nexus.ip:8081/nexus
mvn nexus-staging:rc-release -DserverId=nexus -DnexusUrl=http://my.nexus.ip:8081/nexus -DstagingRepositoryId=abcd-1000 -Ddescription="Release from CLI."
The problem I'm having is that you have to specify the stagingRepositoryId on the command-line. How might I go about accomplishing this?
What I was doing is parsing the output of
mvn nexus-staging:rc-list -DserverId=nexus -DnexusUrl=http://my.nexus.ip:8081/nexus
and then just match the needed repository with your specifique logic. Using python for me was the best solution (but you can do it on your own with any language):
output = subprocess.check_output("mvn nexus-staging:rc-list -DserverId=nexus -DnexusUrl=http://my.nexus.ip:8081/nexus")
for line in output.split('\n'):
if "repo" in line:
stagingRepositoryId = "repo-" + line[8:23]
Considering output as
[INFO] repo_qa-3514 OPEN Implicitly created (auto staging).
[INFO] repo_qa-3518 Implicitly created (auto staging).
[INFO] repo_qa-3521 OPEN Implicitly created (auto staging).
[INFO] repo-2011 OPEN Implicitly created (auto staging).
You will run the second command after parsing as:
mvn nexus-staging:rc-release -DserverId=nexus -DnexusUrl=http://my.nexus.ip:8081/nexus -DstagingRepositoryId=repo-2011 -Ddescription="Release from CLI."
I think what you are trying to do can be achieved readily by using SNAPSHOT and release repository.
So you do your normal development in a SNAPSHOT build and once you are ready for testing, you can create a tag build which removes SNAPSHOT from version in POM. All this can be achieved using jenkins and Nexus.
Also you dont need SVN revision number in your version, instead an incremental build number will be sufficient which can be managed via release plugin.
So to summarise:
Lets say you are working on release 1.0.
So you take a initial branch with pom version as 1.0-0-SNAPSHOT . Here 1.0 represents release number, '-0' represents next tag build number which we plan to deploy.
Now once you are ready for deployment or want your QA team to test. You run a job or a script with maven release plugin to create a tag. A tag build will be created with version 1.0-0 [Snapshot is removed so it will go to release repository] and uploaded to repository also version in branch will be incremented to 1.0-1-SNAPSHOT [So now changes in branch will be made to release and deploy 1.0-1 if any changes are needed]
All the above steps are automated using Maven release plugin and run via jenkins job.
I have the above setup for my work.
OP stated that 'SNAPSHOT' is not in picture.
In that case this post answers the query : automate deployment to sonatype's oss maven repository [Look at the second answer]

Set up a project runner in Teamcity to deploy build artifacts to Artifactory

In our web-application we manage our continuous integration using TeamCity. So far we have manually added required jars and used an ant script to build and deploy our application. Lately we switched to Maven and added Artifactory to the cycle.
I need to know how to deploy our build artifacts from TeamCity to Artifactory.
I added the Artifactory plugin to TeamCity (following this guide) but when trying to add a new build step I can't seem to find any Artifactory related step (which I expect to find).
Am missing something here?
I don't think it is a separate step but actually a set of options at the end of the Maven build step itself (it should be toward the bottom).
See here for more detail:
http://wiki.jfrog.org/confluence/display/RTF/TeamCity+Artifactory+Plug-in.
Specifically, it says "The 'Deploy maven artifacts' option will only be available when using a 'Maven2' build runner."

Disable artifact publishing if build fails in TeamCity

My build scenario is like this (simplified):
Compile
Package (*.zip)
Deploy to test environment
Run tests over the environment
If tests fail TeamCity still publishes artifacts. This is unnecessary and consumes disk space. How can i prevent this? Can't find any check box or something (TeamCity 6.5 Enterprise).
As far as I can tell, TeamCity doesn't have a built-in option to disable artifact publishing if the build fails.
However, in the build script called by TeamCity you could try:
Removing artifact paths from the build configuration, and instead emitting the appropriate TeamCity service messages with your artifact paths only when tests are complete and successful.
Only copying files to the artifact paths configured in TeamCity after the tests are complete and successful.

Resources