TFS command line not working through Jenkins - tfs

I am new to this, so please excuse my ignorance if this is something very basic.
I use the following commands in the 'Execute windows Batch command' tab in a Jenkins job -
cd "C:\Data\Projects\<project name>\00_Mainline"
"C:\Program Files (x86)\Microsoft Visual Studio 12.0\Common7\IDE\TF.exe" get "$/Analytical/<project name>/00_Mainline" /force /recursive
This works well if I type it in a command prompt; but when this is run from Jenkins, I get the following error -
Unable to determine the workspace. You may be able to correct this by running 'tf workspaces /collection:TeamProjectCollectionUrl'.
After going through several threads in this site, I added
pushd "C:\Data\Projects\<project name>\00_Mainline"
to the top of the script. But this didn't help either.
Any ideas?
Regards,
Sudhi

Since you haven't specified otherwise I'm going to assume Jenkins is running under a different user account, in which case there may not be a workspace for the Jenkins account.
In any case, in Jenkins you might need to use the tf workspace command to create a new workspace, and then the tf workfold command to set up a folder mapping before you can do the tf get.

Related

Delete TFS workspace mapping after jenkins job execution

I am trying to run a Jenkins job that uses TFVC plugin. We earlier had a problem with length of the TFS workspace names (exception for length > 75 chars). In order to address this we made a change in the TFVC configuration.
Default workspace name in TFVC: Hudson-${JOB_NAME}-${NODE_NAME}
After change: Hudson-${JOB_NAME}
Post this change the job had one successful run. We are unable to run this repeatedly as the TFS workspace created during the successful run was not deleted. and is throwing the following exception:
FATAL: hudson.remoting.ProxyException: com.microsoft.tfs.core.exceptions.TECoreException: The workspace scanAPI;tfsjenkins already exists on computer ip-XX-XX-XX-XX.
I have tried deleting the Jenkins workspace in pre/post build steps. This has no impact on the TFS workspace.
Additional information: The jobs are being run on a linux node and hence I am unable to run windows commands
You can use Post Build script that use tf.exe to delete the TFVC workpsace, with the delete command.
Create a global environment variable to be able to access the TF.exe easier. for example:
Note: the path to tf.exe it depend to which Visual Studio is installed in the Jenkins machine.
Add a Windows batch command from the scripts menu with the following command:
%TFS% workspace /delete /noprompt /collection:”https://tfs.codeplex.com:443/tfs/TFS27″ “Hudson-%JOB_NAME%;snd\7astlivec_cp”
Replace the URL with your TFS Server URL and change snd\7astlivec_cp with your TFS user. The command is going to delete the newly created TFS workspace.
Another option is to add tf.exe. location to the machine PATH variable and use it directly: tf workspace /delete .......
Update
For Linux, you should be able to use this through team explorer everywhere. It also include a tf command line.
Take a look at Setting up a workspace using Team Explorer Everywhere on Linux
Should be similar on Linux.
Instead of creating the default workspace by specifying workspace name in UI setting, you could also use a Windows batch command to handle this process.
If you want to delete workspace, just add a new post build step, a cleanup command could be added to delete the previously created TFS workspace.
%TFS% workspace /delete /noprompt /collection:"{your-tfs-team-project-collection-url}" "Hudson-%JOB_NAME%;{your-domain-user-name}"
More details your could kindly refer this step-by-step tutorial Jenkins Get Source Code By Specific TFS Changeset

TeamCity hangs when updating sources from TFS

I have configured TeamCity to work with our TFS repo. I have configured the VCS Root and used the "Test Connection" to ensure that the settings are all correct. When I run a build it gets to the "Updating sources" and just hangs there. Here's the build log.
[13:33:45]Collecting changes in 1 VCS root
[13:33:47]Clearing temporary directory: D:\TeamCity\buildAgent\temp\buildTmp
[13:33:47]Publishing internal artifacts
[13:33:48]Using vcs information from server. Reason: no revision information for build configuration "Build Development trunk" and checkout directory D:\TeamCity\buildAgent\work\db23c120e1319dcb on agent
[13:33:48]Clean build enabled: removing old files from D:\TeamCity\buildAgent\work\db23c120e1319dcb
[13:33:48]Checkout directory: D:\TeamCity\buildAgent\work\db23c120e1319dcb
[13:33:48]Updating sources: server side checkout (1m:21s)
[13:33:48][Updating sources] Will perform clean checkout
[13:33:48][Updating sources] Clean checkout reasons
[13:33:50][Updating sources] Building and caching clean patch for VCS root: Development trunk
The checkout folder is empty. Any ideas?
EDIT
I've written a Windows batch file that gets the code out from TFS rather than using TeamCity to do this. My batch file runs perfectly when run from the Windows command prompt but fails when run from TeamCity. I am using the fully qualified path to TF.EXE because TeamCity doesn't seem able to find TF.EXE (even though the path has been added to the PATH environment variable).
My batch file correctly configures the TFS workspace before trying to GET the source code. But it still fails.
"C:\Program Files (x86)\Microsoft Visual Studio 11.0\Common7\IDE\tf.exe" workspaces /collection:http://code-srvr1:8080/tfs/DefaultCollection
"C:\Program Files (x86)\Microsoft Visual Studio 11.0\Common7\IDE\tf.exe" workspaces /s:http://code-srvr1:8080/tfs/DefaultCollection
"C:\Program Files (x86)\Microsoft Visual Studio 11.0\Common7\IDE\tf.exe" workfold //fails!!
"C:\Program Files (x86)\Microsoft Visual Studio 11.0\Common7\IDE\tf.exe" get $/MSM\Development\Trunk /force /recursive //fails!!
The error I am getting is "Unable to determine the workspace. You may be able to correct this by running 'tf workspaces /collection:TeamProjectCollectionUrl'"
But as can be seen I am already specifying the workspace in the batch file.
Any ideas why these commands work from the Windows command line but fail from TeamCity? How do I get them to run from TeamCity?
The solution in my case was to upgrade my Team Foundation Client from 2012 to 2013. There are known timeout issues with the 2012 version and upgrading to 2013 has resolved these.
I had the same issue (TeamCity builds that fetched code from TFS would get stuck indefinitely at the Updating sources stage, blocking the agent).
The solution for me was to make sure that the TeamCity Build Agent ran under the same service account as the TeamCity Server. The server would be able to access the TFS project and instruct the agent to do a build, but the agent itself got stuck when it was not authorized.
When that account mismatch was fixed, it all started working as it should.
As a side note, when the parameter “teamcity.tfs.mode=java” is set, the TeamCity agent does not get stuck, but instead fails with an instructive error message (detailing the current service account name), if it runs under an unauthorized account.

How do you pull multiple TFS repos into a single Jenkins job?

I have a repo that has 2 subfolders $/Repo/project and $/Repo/thirdparty. I need to pull both of those into Jenkins for a single build. Naturally I tried just pulling $/Repo, but this gives me a bunch of other projects along with false polls (it will build every time ANYTHING is checked into $/Repo). I have tried using the multi-scm plugin which works, but does not save the configuration (annoying, but not unusable). I tried using the regular tfs plugin and manually putting the calls for the other repo into a windows command (this did not work even through i bound them them to different folders).
What is the best way to approach this? Some sort of subjob that pulls third party? Fix the multiple scm plugin? Is there some tfs command or trigger to pull a different repo when you pull a project?
I was able to get this working with a job pipeline. It's kinda hacky, but it works.
The program I'm trying to build uses $/Department/Framework/Main (as workspace\Framework), and $/Department/Products/TheProgram/Main (as workspace\TheProgram).
I created three jobs in Jenkins, each "downstream" of the other:
Framework-Get: normal source code triggering on TFS' Project Path of $/Department/Framework/Main. No build step.
TheProgram-Get: normal source code triggering on TFS' Product Path of $/Department/Products/TheProgram. No build step.
TheProgram-Build: No source code control. But the build steps xcopy's the source from the above two steps. Then, you can run a normal build step.
TheProgram-Build's first build step is a windows batch command:
REM ====================================
REM First Get the Framework folder:
rmdir /s/q Framework
mkdir Framework
xcopy /y /q /e ..\..\Framework-Get\Workspace\Framework Framework
REM ====================================
REM Then Get the TheProgram Folder:
rmdir /s/q TheProgram
mkdir TheProgram
xcopy /y /q /e ..\..\TheProgram-Get\Workspace\TheProgram TheProgram
The second build step was a simple call to ant. But you could use msbuild or whatever you like here.
The TFS pluging for Jenkins currently does not support checking out the sources from multiple locations. multiple-scm-plugin might be the answer, but as You pointed out in the question - it's really not an option at this point. There are really, as far I can see it, only to possible solutions for you to test out:
Create a workspace within TFS that will include all the neccesary imports. I use this functionality in my every-day encounters with TFS, although I have never a chance to use that with Jenkins plugin. It might work, it might not.
You can use, and please - this is a quite serious option, at least for me - git. There is a git-tfs and import all of the required projects into git repository. And having them in git will open a bunch of possibilities for you, including using separate repos for every folder, using git modules, git externals... and so on. So, at least for me, it is a valid option, although it seems like an ugly workaround at the first look...
The TFS plugin supports the ability to cloak folders in your $\Repo that you are not interested in. Checkins to cloaked folders will not trigger a build. Unfortunately that may be a lot of folders and you are only interested in two - you would need to maintain the list of cloaked folders as new ones are added.
We avoid the TFS plugin and instead scripted the setup of our TFS workspaces via powershell step using the tfs commandline. Each build specifies the folders it wants and the script takes care to cloak/uncloak the remainder.
My solution to this is to create two Jobs, one that just download your dependency and another to make the build.
In my case I managed the build with Maven properties, for example:
pom.xml
<properties>
<my.dir>../MyDir</wsdl.dir>
</properties>
Jenkins Build
Goals clean package -U -Dmy.dir=${WORKSPACE}/../../another-build/workspace/MyDir
I had to create a workaround myself for Jenkins. This was achieved using both TF and the powershell Snapin Microsoft.TeamFoundation.PowerShell.
Basically the workflow is as follows :
Get-TFsWorkspace (Powershell : To check for the workspace)
TF Workspace /new (To Create a workspace)
TF Workfold /unmap (use this to remove the default $/ mapping which is made during workspace creation)
TF Workfold /map (To map specific locations, ie $/Repo/project)
TF Scorch (to remove any artifacts if there are any)
TF Get (To get the code)
There may be other methods that people have, but this would allow you to use the tf Workfold /cloak functionality as well.
Cheers,
Hope this helps.
Can confirm that that Multiple SCM 0.5 works with the Team Foundation Server plug-in 4.0
The polling does seem to break however.

TFS command line to get all mapping information of a specific workspace

I am trying get all maping information for a specific workspace.
When I try this command, it displays a dialog - which is not what I want.
tf workspace myworkspace
Is there a command that will get all the working folder information and output to the console?
The following command displays the working folder mappings for the workspace in the current directory:
C:\projects>tf workfold
If you want to list the working folder mappings for a different workspace, you can specify the /workspace:workspacename parameter.
C:\>tf workfold /workspace:My_Other_Workspace
You can manipulate the workspace mappings using this command also.
The following example maps the folder C:\DifferentWorkfold to the Team Foundation version control server folder $/projects/project_one
c:\projects>tf workfold $/projects/project_one C:\DifferentWorkfold
See Tf Command-Line Utility - Workfold Command on MSDN for more information
In TFS 2008 and TFS 2010, the command
C:\projects>tf workfold
would indeed display the working folder mappings for the workspace in the current directory.
However, for TFS 2012, this command no longer works.
Now, you just get an error message:
Unable to determine the workspace. You may be able to correct this by
running the command 'tf workspaces /collection:TeamProjectCollectionUrl'
If I knew the TeamProjectCollectionUrl then I wouldn't need to run the workfold command!

Phantom TFS workspace will not let me map to another workspace?

I type this command: tf workspaces into a command line and it tells me there are no workspaces on the machine. I then try the same command on the server, nothing. So I go into Visual Studio 2010 and create a new workspace and try to map the TFS path to my local path. I then get an error that the mapping already exists in another workspace. But I cannot find that workspace on my local or on the tfs server. Any ideas?
You can run tf workspaces /remove:* to clear out your local cache of workspaces. See this link for more details.
I know this is an old question, but I just came across this issue on a Linux machine running TEE (Team Explorer Everywhere). Running "tf workspaces -remove:*" didn't work, because it said there were no workspaces in the cache.
The user was trying to create a new workspace, which worked, but when he tried to map folders, it told him it didn't exist.
When he ran "tf workspaces" on the machine and when I looked in TFS Sidekicks on the server itself, it didn't show any workspaces for him on the Linux box.
If he tried to create the workspace again, it told him that it already existed, but every time he tried to map, he was told it didn't.
We could see the workspace from the tf command line if I did "tf workspaces /owner:", and it required me to run "tf workspace /delete ;" from the command line to get rid of it.
Once we did that, he was able to create it again and everything worked properly.
No idea why that happened, but figured I'd post my answer here just in case someone else comes across a similar issue in the future.

Resources