2

I have the following scenario.

I have 5 build steps in teamcity for a project . I want 5th step to be executed only if the branch is master. The team city process should exit without executing 5th step if the branch is not master. Is it something I can achieve through powershell?

coder coder
  • 53
  • 1
  • 7
  • Just wondering why my question is downvoted? – coder coder Sep 28 '15 at 02:54
  • In the longer-term, this should be made possible with a new TeamCity feature, which is to run steps conditionally. I believe it's currently the [most popular TC feature request](https://youtrack.jetbrains.com/issue/TW-17939) (you may want to up-vote it too). The ticket says it's planned for TeamCity 9.1.x but I don't think it's made it into any of 9.1.0 .. 9.1.3 so it may slip... – sferencik Sep 29 '15 at 06:46

1 Answers1

1

I think the only way to do this is to have a powershell step as step 5 which simply checks the current branch (%teamcity.build.branch%) and errors if its not master, then have the step that you want to run which is currently step 5 as step 6.

Team city doesn't always like to fail if the powershell steps fail, especially in versions before the current one.

To get around this we use the as the source script, but it assumes the script you want to run is in source control:

& "%teamcity.build.checkoutDir%\Path\To\PowershellScript.ps1" "%teamcity.build.checkoutDir%" 
Write-Host "The result was of the previous script was " $LASTEXITCODE
Exit $LASTEXITCODE

The linked answer contains more options depending on which version you are using, so I'll assume you can find exactly how to get a failure to stop the build there.

Community
  • 1
  • 1
Sam Holder
  • 32,535
  • 13
  • 101
  • 181
  • But how can I achieve it when the build step is not command line.If it is an FTP deployer plugin etc how can we achieve this.? – Nevin Raj Victor Sep 28 '15 at 11:57
  • 1
    @NevinRajVictor you need to add a **new build step** before your FTP deployer plugin which just checks the branch and then fails. Then set your FTP deployer to only run if the previous step was successful – Sam Holder Sep 28 '15 at 12:09