Mathematical expressions with TeamCity build number parameter
Completed
Hi all,
I have a commandline build step that will delete the built artifact at the end of the pipeline.
del "C:\My_Artifacts\app_%dep.demoPipeline_Build.build.number%.war"
Let's assume %dep.demoPipeline_Build.build.number% as n,
Now I just need to delete app_(n-10).war file. How can I add this subtract expression in this script. Thanks.
Regards,
Khopi
Please sign in to leave a comment.
Hi! After a brief search on how to do arithmetic in Windows command prompt, I came across this post:
https://devblogs.microsoft.com/oldnewthing/20060504-13/?p=31313
I think something like this should work:
Why do you need it, though? If this is to clean up the artifacts from the old builds, please use the built-in Clean-up feature:
https://www.jetbrains.com/help/teamcity/teamcity-data-clean-up.html
Cheers,
Anatoly
Hi Anatoly Cherenkov,
Thank you for your reply. I tried this but TeamCity didn't recognize "m" as a parameter. I found this in log.
Could Not Find C:\My_Artifacts\app_.war
Pipeline ran successfully but it didn't delete the war.
Reason for the need - I have separate directory for built war files. But I need only recent war files and I need to maintain the storage consistency automatically.
Regards,
Khopi
As I understand the problem is that the build configuration now shows the required m parameter. You resolve that by adding a build configuration parameter named m with the value %m%.
Hi,
This is working for me...FYI. Thanks.
set /a oldBuildNumber = %dep.demoPipeline_Build.build.number% - 10
del "C:\My_Artifacts\app_%%oldBuildNumber%%.war"
Regards,
Khopi