1

According to other SO question I have a test that sporadically fails in tfs, which means that one of the build-steps sometimes fails.

The build step maybe fails every 10th to 20th time it is run.

I am therefore wondering, if there is a simple way to rerun successful build steps on tfs?

nelion
  • 1,712
  • 4
  • 17
  • 37
  • I'm not fully understand, if the test will fail so you want to re-run the build automatically? – Shayki Abramczyk Jun 25 '19 at 07:06
  • @ShaykiAbramczyk No, I would like to re-run the successful build-step again and again n-times and hopefully not fail. If it fails, I will again have to make some changes and then make a new commit. – nelion Jun 25 '19 at 07:12
  • @ShaykiAbramczyk a simple way is to fx place a space in the code and make a new commit, but that will force all the build steps to run again and will mean a lot of non-productive time spend, I think. – nelion Jun 25 '19 at 07:19
  • Now I understand :) interesting request... I can think about a powershell script with many lines of msbuild, what do you think? – Shayki Abramczyk Jun 25 '19 at 07:25
  • @ShaykiAbramczyk No need, but thanks. Also there are some good tutorials for that online, so I should just be not-lazy, but if they had a rerun-button or something that simple, that would be great in my situation. Just wondered if anyone else had the same issue and found an easy workaround :) – nelion Jun 25 '19 at 07:34
  • There is no re-run button for one step, I don't think there is a feature to achieve that. an easy workaround can be powershell script with loop for msbuild, do you want an example? – Shayki Abramczyk Jun 25 '19 at 07:58
  • @ShaykiAbramczyk If you have an example by hand / link, then yes, please. – nelion Jun 25 '19 at 08:02
  • See my answer :) – Shayki Abramczyk Jun 25 '19 at 08:08
  • If a test sporadically fails **fix or remove the test**. A test that isn't a consistent indicator is actively detrimental to your codebase. – Daniel Mann Jun 25 '19 at 14:15
  • @DanielMann I agree. I 'fixed' it and therefore had to figure a way to re-run the buildstep/tests on tfs n-times to see if I could count on the new fix or if that also failed sporadically. But of course a sporadically failing test needs attention. – nelion Jun 26 '19 at 11:00

1 Answers1

0

I don't think there is a feature to run a task n times, but here a workaround to run the build many times (PowerShell script):

$times = 30
For ($i=1; $i =lt $times; $i++) {

    Write-Host "*** Start to build $i time ***"
    # I use VS 2019 Enterprise, change the path if you have another version
    cd "C:\Program Files (x86)\Microsoft Visual Studio\2019\Enterprise\MSBuild\Currnet\Bin"
    # Change the folder/sub folder to your solution path
   ./msbuild.exe "$(Build.SourcesDirectory)\{your soultion name}.sln"
}

enter image description here

Shayki Abramczyk
  • 36,824
  • 16
  • 89
  • 114
  • Great - thanks. It's running and giving a nice status back with no errors. The build steps don't affect my tfs though, but should the outcome not be the same anyway? So if running the script 30 times for example, and I do not get any errors, should I then presume/trust, that it also goes for my tfs-build-steps? – nelion Jun 25 '19 at 10:21
  • I don't know exactly why you build step fail, you just need to run it a few times and check i you can trust it.. – Shayki Abramczyk Jun 25 '19 at 10:54