TeamCity step needs to be skipped on build failure condition
Asked Answered
C

3

6

From my observations around how TeamCity works, I noticed that build failure conditions are evaluated after all the steps are done executing. This is quite annoying because I can't have a step which would not execute if any of the build failure conditions have met.

I'm not referring to the common build failure conditions, such as "at least one test failed". I'm referring to the manually added failure conditions such as on metric change.

When I check the build log, I clearly see that all the steps are executed, and only in the end it evaluates the build failure conditions, and logs the respective errors if any. But that's too late in the process as the conditional step (which had to fail based on "Execute Only if build status is successful") has already executed.

Question: how can I achieve this?

As you can see from the above, I already tried to have a conditional step and added the build failure condition, but cannot achieve the desired result.

Addition for clarity:

Basically, I have a step which deploys the application. However, my expectation is that I should not deploy if the build failure conditions are met. Example of build failure conditions that I have is on metric change. Obviously, this I can express as build failure condition, and I can have the build step that fails in case build status is not successful. However, it seems that's not how the build step is going to behave, so I'm puzzled (I thought that's the purpose of the condition on the build step). What am I missing?

Creswell answered 16/2, 2016 at 18:19 Comment(0)
S
1

The build and deployment 'build configurations' should be separated.

If the build 'build configuration' completes successfully (without activating the failure conditions) then this would trigger the deployment 'build configuration' to run.

Spikelet answered 22/3, 2018 at 10:27 Comment(1)
That's what I ended up doing. However, that does not answer the issue. The status I was referring to was of step, and next step condition is set to continue only if the previous step succeeded. Something does not add up. That was my concern - about the step, not about the build configuration.Creswell
B
1

The recent versions of TeamCity have an option "Execute step" with "Only if build status is successful" - and this option should consider build failure conditions on the server as well.

Bollix answered 21/5, 2020 at 15:25 Comment(0)
M
0

It's because build failure conditions are checked when all the build steps are complete. And it makes sense, because for a condition like metric change you ought to wait for the build to complete, I mean you cannot consider calculating artifacts size or looking for a specific text in logs or something similar until the build is complete .

That said - for your case, you should consider writing build steps that exit with a non zero exit code on failures and then you can use If all previous steps finished successfully option in Execute step of build step.

Masinissa answered 17/2, 2016 at 8:47 Comment(5)
So, you are suggesting that the step with unit-tests should exit with non-zero code in case the build failure conditions are met? but how can I tell step to return non-zero code based on the build failure conditions?Creswell
Not on the basis of build failure conditions - if you are running unit tests and a unit test fails, the step which is running unit tests should return a non zero exit code. May be a bit more information about how are you running unit tests will be helpful. For example, if you use teamcity NUnit plug-in to run Nunit tests, it does exit with a non-zero exit code if a test failsMasinissa
I got your point. But unit-tests are not failing, only build failure condition is true. This means: all unit-tests passed, but coverage dropped by N percent. I have a build failure condition that checks if the coverage dropped, and if it dropped then the build will be marked as failed. Unit-tests don't fail though. At the end of the build, it's marked as failed, so the build failure condition works fine. I just need to skip last step (deployment) if the coverage dropped (means if the build failure condition is met).Creswell
Right Okay - I am afraid its not possible to skip deployment on the basis of a build failure condition. You should rather try having deployment as a separate build and set it to trigger on a successful Continuous Integration build. Finish build trigger is the way to do it.Masinissa
Ok, then I wander what's the purpose of the condition on the build step, where we can say to execute only if build status is successful. Does this mean the status of the previous build, not current build?Creswell

© 2022 - 2024 — McMap. All rights reserved.