4

I'd like to commit a file to TFS repository through the tf command-line tool and link the commit to a TFS work-item. How do I do it?

I've gotten as far as committing my file, but without a link to the work-item.

My command adds a new file and commits the changes:

%> tf add foo.cpp
%> tf checkin foo.cpp -comment:"this is cool, but no work-item!"
KlingonJoe
  • 815
  • 8
  • 17
  • You can use `git commit -m "my message #22003"` and it will associate the work item. I totally expected this to work with `tf vc checkin`. But it doesn't. What a shame. – John Henckel Dec 14 '18 at 20:32
  • Another one to look at: https://stackoverflow.com/questions/27578079/how-to-link-a-tfs-workitem-to-another-using-command-line – Mladen Mihajlovic Aug 27 '21 at 12:07

2 Answers2

3

Unfortunately, you can not do this using tf.exe command line. If you need to use the -noprompt parameter for automation then you're likely out of luck.

Without -noprompt parameter, simply do this in work-item bar from UI. Select the workitem from your query and check the √, finally check in changes.

enter image description here

If this is a checkin policy in your company, you could also use the override parameter to bypass it as a workaround.

tf.exe checkin c:\workSpaceFilepath /comment:"some comment" /override:"Automated Build Process"

More details please take a look at this similar question: Can I check in to TFS from CLI with a work item association?


Update

tf checkin -associate

May do the trick as KlingonJoe says. However - associate is out of date

This may work with earlier version of TFS\VS such as VS2010 or team explorer everywhere. But it's not work for TFS2015 and VS2013 and above at least.

Moreover, to ignore the prompt, you could directly use /noprompt in your tf check in command. More info you could check this tutorial.

Community
  • 1
  • 1
PatrickLu-MSFT
  • 49,478
  • 5
  • 35
  • 62
  • 1
    Another way is using powershell script and reflection on the TFS object mode. How to do this please refer the answer from *philip* in this link http://www.kinook.com/Forum/showthread.php?t=4502 – PatrickLu-MSFT Mar 08 '17 at 03:10
  • Didn't even know that the prompt popped up, which would explain why the machine kind of hangs there after I press enter. I need to figure out how to push the window through putty to my windows desktop. – KlingonJoe Mar 08 '17 at 10:54
  • 1
    Patrick - I'm running TF from Linux. The TF version that we've installed there is version 14.0.3 – KlingonJoe Mar 09 '17 at 21:23
  • @KlingonJoe Thanks for the sharing. TFS doesn't have this version number(14.0.3), you can check [here](https://blogs.msdn.microsoft.com/tfssetup/2013/11/21/what-version-of-team-foundation-server-do-i-have/). You must be using [**Microsoft Team Explorer Everywhere 2015**](https://www.microsoft.com/en-us/download/details.aspx?id=47727) It's make sense. seems `- associate` parameter is still working with Team Explorer Everywhere. – PatrickLu-MSFT Mar 10 '17 at 06:40
  • Based on the instructions on the website you linked, the TFS version is: 14.102.25423, that makes more sense (Update 3). I'm not sure what version the TF tool on Linux is returning. Let me inquire some more. – KlingonJoe Mar 10 '17 at 15:22
3

This line command worked:

tf checkin -associate:55555 ...

It correctly associated the changes with work item 55555 and I was able to ignore the prompt.

Here is a link to the -associate option: https://msdn.microsoft.com/en-us/library/gg475882(v=vs.100).aspx

KlingonJoe
  • 815
  • 8
  • 17
  • Which version of TFS and VS are you using ? Are you using team explorer everywhere which the TFS plug-in for Eclipse not team explorer in VS... Your link is out of date. Either you are using tee or another reason is you are using VS2010. Which this command works on that version. Your answer maybe not so comprehensive. Actually this command with `-associate` parameters is not work for TFS2015 and VS2013 above at least. To ignore the prompt, you could directly use `/noprompt` More info you could check this [tutorial](https://www.visualstudio.com/en-us/docs/tfvc/checkin-command). – PatrickLu-MSFT Mar 09 '17 at 10:02
  • See the first comment @JohnHenckel -- you are correct -associate has been deprecated. It appears that my Linux installation of the TF command is quite old. – KlingonJoe Nov 19 '18 at 05:40