Exclude files from Teamcity push pakage

I am using teamcity’s “OctopusDeploy: Push Packages” option to create and push zip file to octopus. I want exclude Web.config, Web.Release.config and Web.Debug.config files. I tried to remove Web.Config using several methods. None of them seems to be working.

P.S: I use "Publish packages as build artifacts: " option.

I need to push All files in NorthwindSolution Except Web.Config as a zip file (it’s even better If I can exclude all Web.config, Web.Release.config and Web.Debug.config)

Here are few of the method the method which I tried:

  1. NorthwindSolution/** => Release.%MajorVersion%.%MinorVersion%.%build.number%.zip-:NorthwindSolution/Web.config

  2. NorthwindSolution/** => Release-:NorthwindSolution/Web.config.%MajorVersion%.%MinorVersion%.%build.number%.zip

  3. NorthwindSolution-:NorthwindSolution/Web.config => Release.%MajorVersion%.%MinorVersion%.%build.number%.zip

and few more tried. None worked though.

Hi @chamodshelan,

Thanks for reaching out.

Octo pack actually doesn’t have an exclude option, so what you would want to do is move the items you do want to package into a folder, then run the package step on that folder and push that.

Do you think that will work for your use case?

Please let me know what you think.


1 Like

Hi @jeremy.miller Thank you for the response, Let me further clarify my issue

So basically what I do is, I push my package from visual studio to Bitbucket. Then teamcity pull that package and build it and push it to octopus where I deploy that package. So can you please refer me how to move my items to a different folder without web.config file, and it has to be automated. Is there any way to do that?

Basic Idea: Visual Studio -> Bitbucket -> Teamcity (Build and Push to octopus) -> Octopus
My Build steps are follows,

Thank you so much…!


You’re very welcome!

Are you utilizing Octopack within step 2?

If so you will need to do something similar to this code in an additional build step:

$checkOutDir = "%teamcity.build.checkoutDir%"
$publishDir = "$checkOutDir\src\rollingdeploy-webapp\bin\Release\netcoreapp3.1\publish"
Write-Host "The directory is $publishDir"
$to = "$checkOutDir\src\rollingdeploy-webapp\bin\Release\netcoreapp3.1\publish\final"
if(-not (Test-Path -Path $to))
	New-Item -Path "$checkOutDir\src\rollingdeploy-webapp\bin\Release\netcoreapp3.1\publish" -Name "final" -ItemType "directory"
Write-Host "The final dir is $to"
Get-ChildItem -Path $publishDir | % { 
  Copy-Item $_.fullname "$to" -Recurse -Force -Exclude @("web.config") 
  Write-Host "Copying $($_.fullname)"

This is not fully tested so please test it thoroughly in your environment before putting it into production.

Once this is finished, you will octopack from the $to directory and push the resulting package.

If you are using octopack, we recommend using the octo.exe pack function instead.

Please let me know what you think.


1 Like

@jeremy.miller Thank you so much for the help, Using post-deployment script seems kind of easy but not convenient enough. But for now, I decided to stick with that method. Anyway, Thank a lot for the support and really appreciate it.

Hey @chamodshelan,

You’re very welcome!

A post-deploy script to delete the files will also definitely work. The only overhead there is having to remember to do it on every deploy of that package (which may only be once).

If you do end up wanting to implement this into your build steps and want a hand, please feel free to reach out to us.

I hope you have a great week.


1 Like

This topic was automatically closed 31 days after the last reply. New replies are no longer allowed.