Can teamcity check out the source of the last successful build?

Ok, here's the scenario that I'm wanting, it's a code quality gate to ensure that something silly doesn't happen.

 

The scenario is that we have an API which is public.  The policy is that we are allowed to extend the API, but adding more methods or parameters.  However, we don't want to be able to reduce the API without manual intervention (i.e. make it awkward to do, like disabling a build step)

What I want to do is have a build step compare two files to see if it's ok to continue.  (no need to go into the details of writing a file comparison routine, already know this part)

So where's the problem?

The problem is that in order to get the old and new file to do the comparison, I need to check out the source code from the previous successful build, and the current head in the VCS.

Getting the current version of the file is no problem as teamcity does that out of the box.

 

So the problem is that I need to get access to the source code for the last successful build of the code.

To add the the fun can games, we use feature branching, so it's possible that the  current build is in a branched names "feature/F1234" but the last successful build is in "develop".

 

I'm hoping to not have to use build artifacts to save the API files that I want to check (will do that if there's no alternative) what I'd much prefer to do is check out the source directly from the VCS.

 

So in the build configuration I want to do this...

 

1. check out current version of the code to build (current VCS implementation will work for this)

2. check out version from last successful build (this will check out only the portion of the source that I'm interested in to a seperated folder)

3. run build steps

4. run new build step to compare api file located in current version against the copy in the seperated folder if it exists (i.e. execute an exe passing the two file locations)

 

Any suggestions?

0
2 comments

I've done some investigation on this and don't think it's a viable approach.   Firstly, making a circular dependency to get artifacts from the last build on the same branch isn't a good idea.  Especially with feature branching, as the first build of a branch may not have a previous successful build.  So you can't start the cycle going easily.

 

Looking closer as the VCS sources, it appears that there isn't a way to specify that I want to check out an older build, at least I've not come across something.

So it looks like this is something that's not really viable using TeamCity's feature set.  I'm turning my attention to other approaches which will be less elegant.

0

Hi,

 

So, first of all, what would make the most sense would be to, instead of comparing the code, compare artifacts. You could normally set up an artifact dependency. As you point out, there is a limitation for new branches, as new builds will not have an initial one to reference.

 

There is no explicit feature to check out, at the same time, two different revisions. You would need to take care of it yourself if you want to get the revisions

In your scenario, what would make the most sense would be to:

-Have the VCS as you have it now, but modify the "checkout mode" to "don't checkout files automatically"

-Have a first build step that downloads whatever you need to the folders you want to. In order to download the previous revision you can check the last successful build results via the REST API, find out which change it had applied, then pull that.

-Then proceed as required.

 

Another possibility would be to have a second copy of the VCS Root (you would need to ensure they're set up separately), use checkout rules to forward the contents into a separate folder and then, again, on a first step, change to the appropriate revision. This would be similar to the previous option, but wouldn't require to manually pull changes, just to change the revision in one of them.

0

Please sign in to leave a comment.