Tag a Build in TeamCity from another Build - teamcity

We have a Build that compiles and creates an artifact. Then we have another Build that uses the last Compile build and Deploys it to the proper environment. Once that is complete, I have to go and Tag the build in TC that it was pushed to the environment. Is there a way that I can tag the Compile Build that is was deployed using the Deploy Build?

I'm not aware of an easy way to do this (i.e. through a TeamCity configuration setting) but you probably could accomplish this using the REST API from your build script.

If you are using TeamCity 6 or above because you have a build dependency chain from the Deployment Build to the Main Build either through artifact dependencies, snapshot dependencies or both you can just tag your Deployment Build. This is because the UI will show you a tree view of the dependencies that the deployment used and you can navigate to the actual build.
One thing you can do, and in my opinion should do, is to tag your source control from TeamCity if you are using a source control that supports tagging/labelling. You should probably set your Deployment Build up with a snapshot dependency as well as the artifact dependency, especially if your build files are in the same repository. On your Main Build you should get TeamCity to label your repository on a successful build with something like "build-1.2.3.4". Then on your Deployment Build you should get it to label the repository after a successful build with "deployed-1.2.3.4". If you deploy to different environments then you can get it to label the repository accordingly.

Related

Can I set the default deployment for any project in Maven?

On our TeamCity build server every project now specifies the deployment repository either using the command line argument -DaltDeploymentRepository or <distributionManagement> in the project's POM file.
However we are planning to move to Nexus 3, and there would be considerable amount of work to make sure that all projects are configured correctly. There is also the fact that the deployment procedure has to be communicated with every developer.
Is it possible to specify the Maven deployment target in settings.xml or other so that unless otherwise specified any project that does a deploy on TeamCity will get deployed to the correct repository?
...in settings.xml...no:
Servers
The repositories for download and deployment are defined by the repositories and distributionManagement elements of the POM.
...or other...yes:
Create a (or, if already existing, use the) parent POM from that all your projects inherit.
I figured out another solution: TeamCity meta-runner. By producing a working build you can extract a meta-runner which is kind of like a build-step macro.
If you first get the deployment working you can extract a meta-runner using Actions->Extract meta-runner... in the TeamCity build configuration.
This shows an editor for the XML that specifies the build-runner. Remove all the non-deployment specific build steps, and you can provide build step parameters in the meta-runner/settings/params block. You will probably need to add pomLocation and the specify %pomLocation% in the build step's <params> block.

Alternative builds using different set of dependencies on related projects

I have several projects with dependencies between them and in the production build all the projects are packaged into jars, published and the main project simply adds dependency on these jar files.
During development and CI however I would like the main project to have dependencies on the related projects and build them too as part of the process (not compile, deploy and then build next, but rather compile all together).
This mans that in production I would have:
compile group:'com.me.aaa', name:'myCommonProj', version: '1.0.0'
while for the development builds I would like to have:
compile project(':myCommonProj')
Option #2 however requires the settings.gradle file.
How can I accomplish this setup?
I'd apply gitflow to the project and work in the following way:
in dev branch I'd keep compile(':myProject') dependency along with appropriate setting.gradle file.
in master branch I'd keep only fixed dependencies.
This scenario isn't very comfortable however because dev branch would be merged partially (fixed vs local dependencies), but it can be quite easily done. On the other side, working this way will prevent you from keeping strange logic in build script.
Second option is if it all un build.gradle and settings.gradle. CI server should expose build numbers and other environment variables. They can be used to include appropriate dependencies depending on environment.

Build Once, Deploy Anywhere, with Maven, Jenkins, and Artifactory

I'm in the latter stages of setting up a CI environment for my project. I'm using Maven, Jenkins and Artifactory Pro and can successfully build my project and deploy it's artifacts to Artifactory. I have also written a bash script to retrieve the resulting artifacts of a specific build from Artifactory and copy them somewhere.
The main part I'm missing right now is automated versioning. I've looked at enabling Artifactory release management, which is really cool, but involves the rebuilding of the project. I'm really trying to follow the mantra of 'Build Once, Deploy Anywhere', so any rebuilding is a no-no.
My question boils down to: Is there an automated way (either with one of the aforementioned tools, or a plugin) to handle versioning, without rebuilding an artifact?
Artifactory Pro allows you to easily extend Artifactory's behavior with your own plugins written in groovy. (https://www.jfrog.com/confluence/display/RTF/User+Plugins)
You can find here, an example of Promote extension, that will change your artifacts versions without the needs of new build.
You can find more usefully examples in the GitHub "artifactory-user-plugins" repository.

Maven deploy configs in pom.xml VS jenkins post-build action

Actually I see two alternatives how can I deploy my project to NEXUS:
Configure distributionManagement and deploy-plugin in pom.xml. That in jenkins I should only call mvn deploy and my project will be deployed to the environment
Create in Jenkins Post-build Actions -> Deploy artifacts to maven repository, where I can set repository URL, repository ID and so on
Question
What is pros and cons of each approach comparing with one another?
If you are configuring the deployment in Jenkins build configuration you are doing two things
you are separating the deployment from the project itself and therefore potentially can have different deployments for the same project
you remove the deployment setup from your version control setup/your source code
If you are leaving it in the pom using the default Maven setup you can run deployment of the project without modification from the commandline on any machine that has the credentials set up correctly. This can greatly help wit troubleshooting and it makes the setup independent of whatever CI server you use.
Both approaches as well as more custom setups like using the Artifactory Build Integration or the Nexus Staging Maven Plugin usage are fine. It will mostly depend on what you are aiming to achieve.
Personally I believe that the configuration should not be isolated to Jenkins and should remain with the project in the pom. But that is just my 2c.
Thanks for adding the Artifactory tag, now I can give you one more option - Artifactory Build Integration. With Artifactory Jenkins plugin you can configure your deployment options (target repository, whether or not you want to deploy build information, environment variables and custom properties etc.) without polluting your developers pom with ci-eyes only information.

Dependency on non-maven module

The entire java project has an ant build; however couple of module(s) have maven build too.
My new module (maven built, say A) has dependency over an existing module(or simply a folder?, say B) which is being built using ant which just packages the src into jar and drops it inside the project.
Maven build for module A fails (unable to locate moduleB files); Options -
1. Package module B using maven, push to m2_repo
I do not want to go with this option.
Please let me know what are the other options available for the same.
If you have control over the source of all your modules, and if you decided that Maven is your way to go forward, then I recommend to to go all-in as soon as possible. If you do not then you will have continuous problems for the two build strategies to play along. And not only during build time but also at deploy time when it is time to collect all your runtime dependencies. Unless you build one uber-JAR as your only deployable artifact.
If your modules will (almost) always release in sync, then consider using a multi-module project setup.
When I say "all-in" then I do not mean that you have to give up Ant completely. You can use the maven-antrun-plugin to kick of your existing ant builds.
You should also consider running your own repository server, e.g. Nexus, to take full advantage of your maven builds.

Resources