In my TFS 2017 build definition, I am trying to copy a folder with a specific name (Package) towards my Artifacts directory. I am only interested in the specific folder itself, not in it's parent folders.
Can someone enlighten me on how I should make this work?
Current configuration for the Copy Files task:
Source: $(agent.builddirectory)
Contents: **\Package***
Target Folder: $(build.artifactstagingdirectory)\MyArtifact
This results in the following folderstructure while my only interest is the Package folder:
\MyArtifact\folderX\s\folderY\folderZ\folderA\Package
With TFS2017update1 and above, VSTS, you could simply check Flatten Folders under Advanced option in Copy Files Task. The easiest solution for now.
This will flatten the folder structure and copy all files into the
specified target folder.
Not sure if you are working on 2017 release version, and there is no Flatten Folders option. You need to specify the copy root if you want to copy files only without folder structure. You can use $(Build.StagingDirectory) as a target for this. Afterwards use the Publish task with $(Build.StagingDirectory) as copy root and publish everything from this root to the drop.
Detail step and screenshot please take a look at the answer from Eddie in this question: Copy one file in target directory on deploy from visual studio team services
If the relative path to "package" does not change, you can specify the detailed path in "Source" to achieve the feature you want.
For example, configure the Copy Files Task:
Source Folder to: $(agent.builddirectory)\folderY\folderZ\folderA\Package
Contents to: **
Target Folder to: $(build.artifactstagingdirectory)\MyArtifact\Package
You will get the folder structure you want.
While all answers were correct in some way, it was not what I intended to achieve.
I ended up creating my own PowerShell script to copy the package folder and it's contents to the Staging Directory:
$BasePath = [System.IO.Path]::GetDirectoryName("$(SolutionPath)")
$Search = "PackageTmp"
$Destination = "$(Build.StagingDirectory)"
Get-ChildItem -Path $BasePath -Filter $Search -Directory -Recurse | Copy-Item -Destination {Join-Path $Destination $(ArtifactName)} -Recurse -Force
Related
In a build, we have Copy files from the task. The problem we have is the source folder itself is copied to the destination. We'd want the contents of the source folder to be copied to the destination folder, not the folder itself. Is there any way to do that?
I tried a wildcard but that doesn't work. It seems it needs a path itself. An issue of this could be that the source is named 'X' but the destination is named 'Y' (it was setup before this build and IIS is pointing to this folder). Can we have the source folder be renamed in the build maybe?
That would be name_of_sourcefolder\**\* for all files and subfolders of just name_of_sourcefolder\* for all files.
This has to be set in the Contents part of the task.
IN TFS 2017 on-premises site, I've put together a TFS build that generates several database builds and SSIS package builds. it produces the desired dacpac and ispac files. However, when created, these files are placed in a hierarchy, based on the particular project structure. It looks something like this:
Database1
\bin
\Release
\database1.dacpac
Database2
\bin
\Release
\database2.dacpac
ssisPackage
\bin
\Development
\ssispackage.ispac
I would like to copy all of these files (*.dacpac and *.ispac) to a single
directory (flattened) when pushing them out to my team. However, the Copy Files task is copying them and preserving the folder structure.
The Contents block of the "Copy Files" task is:
**\bin\$(BuildConfiguration)\**\*.dacpac
**\bin\Development\*.ispac
and the Target Folder is
$(build.artifactstagingdirectory)
Is there a way to move this files to the target folder without the folder hierarchy, resulting in:
OutputFolder
\database1.dacpac
\database2.dacpac
\ssispackage.ispac
Thanks for the advice
Refer to these steps to achieve your requirement:
Create a bat file with code below and add to your project, then check into source control (%1 means first argument, %2 means second argument)
Code:
pushd %1
for /r %%a in (*.pdb) do (
copy "%%a" %2
)
popd
Add Command Line build step to your build definition
Note: This code is used to copy pdb files, you need to modify it per to requirements.
I have created a Copy and Publish Build Artifacts build step in TFS 2015 with the following parameters:
Copy Root: $(build.sourcesdirectory)\bin\Installers
Contents: **
The according to https://www.visualstudio.com/pl-pl/docs/build/steps/utility/copy-and-publish-build-artifacts it should not copy the subdirecttories but unfortunately it does it!
How to copy and publish build artifacts whitout subfolders?
Please add the suffix of the files after **, then you won't get the subdirectories. For example, in the following setting, you'll only get .txt and .dll files under $(build.sourcesdirectory)\bin\Installers, but you won't get .txt and .dll files in any sub folders under $(build.sourcesdirectory)\bin\Installers:
You can use **.* instead of **.
in Jenkins, I have a job downloadAgents that is responsible of creating a folder and populating it with some files. Then the folder is saved as an artifact with the following folder structure
dev\downloadAgents\target\dependency\ios
Then I need to copy the contents of the ios folder into the workspace of another job (into a specific folder).
I have added the Copy artifacts from another project step. And it does copy the artifacts, but it copies the full path
\dev\downloadIosAgents\target\dependency\ios
How can I tell jenkins to copy only one folder ios and everything that is inside it and, do not copy all folders that are before ios.
Also if there are already files in the destination folder, will it merge the 2 folders?
You can use regex for your copy (under "Artifacts to copy")-
dev\downloadAgents\target\dependency\ios***.*
** - all folders under ios
*.* - all file types
You can also specify the target directory, and you also have a flag for "Flatten directories". This will move all the files without the hierarchy of the folders (flat to your target directory)
Feel free to look at the plugin's home page:
https://wiki.jenkins-ci.org/display/JENKINS/Copy+Artifact+Plugin
In CopyArtifacts plugin specify the pattern: \dev\downloadIosAgents\target\dependency\ios\*.* or \dev\downloadIosAgents\target\dependency\ios\** - I don't remember exactly.
That should do the job.
We have a solution with many Class Library projects. These produce a set of DLLs each.
The way we want to deploy these is to install them to the GAC. So we can have a script (BAT file) to run Gacutil /i on the DLL.
We currently use TFS to build our solution using the default TFS build template.
We need TFS to build the solution, and produce folders for each project (the release package) with the DLL and install script. So all we need to do after that is go to the drop folder, see a list of folders (release packages), and everything we need to install each class library in within the folder.
e.g.
-> Dropfolder
-> Proj1
-> Proj1.dll
-> Install.bat
-> Proj2
-> Proj2.dll
-> Install.bat
-> Proj3
-> Proj3.dll
-> Install.bat
Update:
For each project I have set up the following Post-Build event:
powershell -executionpolicy Bypass -file "$(ProjectDir)Deployment\CreateDeploymentPackage.ps1" -Bin $(TargetDir) -Source $(ProjectDir) -Name $(ProjectName)
In my source I have the said powershell script Deployment\CreateDeploymentPackage.ps1
The powershell scripts looks something like this:
param(
[string][parameter(mandatory=$true )] $Bin,
[string][parameter(mandatory=$true )] $Source,
[string][parameter(mandatory=$true )] $Name)
$packagePath = "$Bin$Name"
New-Item "$packagePath" -type directory
Copy-Item *.dll $packagePath -recurse
Copy-Item "$deploymentScripts\Install.ps1" "$packagePath" -recurse
Copy-Item "$deploymentScripts\Uninstall.ps1" "$packagePath" -recurse
Now this works when I build locally. It picks up all dlls in the bin directory and copies them into the folder.
This also works on the TFS build server, but only when building the project by itself.
The problem lies in how TFS builds all the dlls in my solution into a single bin output directory.
Question
Is there a way to copy only the dlls that are related to the project (including dependencies) without explicitly listing each dll?
Is doesn't matter in the slightest, you can setup your source control what ever best suits you needs.
Have a read of this MSDN Article that explains how to control where TFS places your assemblies. For your install.bat files you can check them into TFS and use a post build step to copy them with your output. If you really wanted you might be able to create a custom TFS Activity to generate them as part of the build - have a read of this Blog Series by Ewald Hofman, to get your head around customising TFS builds.