简体   繁体   English

TFS Build Defintion中的Powershell脚本

[英]Powershell Script within TFS Build Defintion

Using Windows Workflow in TFS2010, I set up a PS script to run at end of build process. 在TFS2010中使用Windows Workflow,我设置了一个PS脚本,以便在构建过程结束时运行。 Followed example in http://www.ewaldhofman.nl/post/2010/11/09/Part-14-Execute-a-PowerShell-script.aspx to a T and it appears correct in Process section of build definition. 以下示例见http://www.ewaldhofman.nl/post/2010/11/09/Part-14-Execute-a-PowerShell-script.aspx到T,它在构建定义的Process部分中显示正确。 However, no matter what I set arg to the dir path of script, the result is always... 但是,无论我将arg设置为脚本的dir路径,结果总是......

The term '.\\DataServiceCpy.ps1' is not recognized as the name of a cmdlet, func tion, script file, or operable program. 术语“。\\ DataServiceCpy.ps1”未被识别为cmdlet,功能,脚本文件或可操作程序的名称。 Check the spelling of the name, or if a path was included, verify that the path is correct and try again. 检查名称的拼写,或者如果包含路径,请验证路径是否正确,然后重试。

I've tried 10 variations of the path. 我尝试过10种不同的路径。 I enabled PS scripts to run on build server and I can run the script successfully from cmd prompt. 我启用了PS脚本在构建服务器上运行,我可以从cmd提示符成功运行脚本。

Anything obvious that I am overlooking? 我忽视了什么明显的东西?

many thanks... 非常感谢...

In TFS 2013 (not sure for others) exists RunScript activity which is placed into "Team Foundation Build Activities" in Toolbox. 在TFS 2013中(对其他人不确定)存在RunScript活动,该活动被放置在Toolbox中的“Team Foundation Build Activities”中。 I prefer that activity when I want to execute some custom script. 当我想执行一些自定义脚本时,我更喜欢该活动。

To use this you need to first create arguments (at least one for script path)! 要使用它,您需要首先创建参数(至少一个用于脚本路径)! To create arguments follow this post . 要创建参数,请遵循以下文章

After you created argument for script path you need to navigate yourself to "Metadata" argument on arguments tab. 在为脚本路径创建参数后,您需要在参数选项卡上导航到“元数据”参数。 Add your created argument and also add following statement in "Editor" field: Microsoft.TeamFoundation.Build.Controls.ServerFileBrowserEditor, Microsoft.TeamFoundation.Build.Controls 添加您创建的参数,并在“编辑器”字段中添加以下语句:Microsoft.TeamFoundation.Build.Controls.ServerFileBrowserEditor,Microsoft.TeamFoundation.Build.Controls

After that go to "Properties" on RunScript activity and into FilePath insert following statement: AdvancedBuildSettings.GetValue(Of String)(" PUT_HERE_YOUR_ARGUMENT_NAME ", String.Empty) 之后转到RunScript活动的“Properties”并进入FilePath,插入以下语句:AdvancedBuildSettings.GetValue(Of String)(“ PUT_HERE_YOUR_ARGUMENT_NAME ”,String.Empty)

Note that you need to insert in last statement exactly name of your argument which you created for script path. 请注意,您需要在最后一个语句中插入为脚本路径创建的参数的确切名称。

After you are done: 完成后:

  • check in your changes; 检查你的变化;
  • go to build definition "Process" tab and press "Refresh" button in "Build process template" section; 转到构建定义“Process”选项卡,然后按“Build process template”部分中的“Refresh”按钮;

These steps will allows you to browse your source control and choose your script which you want without providing path. 这些步骤将允许您浏览源代码控件并选择所需的脚本而无需提供路径。

If you don't need to insert new activity, you can just modify old arguments. 如果您不需要插入新活动,则只需修改旧参数即可。

I did it the same way using the same blog and it worked for me. 我使用相同的博客以同样的方式做到了它,它对我有用。 The only difference that I see is that my Powershell script lives in the solution/project folder and in the build definition I specify the powershell script using a relative path. 我看到的唯一区别是我的Powershell脚本存在于解决方案/项目文件夹中,而在构建定义中,我使用相对路径指定了powershell脚本。 Having a relative path works well with ConvertWorkspaceItem activity. 具有相对路径适用于ConvertWorkspaceItem活动。 You may want to check (output) the file path that you get after your ConverntWorkspaceItem activity to see if that is the right path. 您可能希望检查(输出)在ConverntWorkspaceItem活动之后获得的文件路径,以查看它是否是正确的路径。

I hope that helps. 我希望有所帮助。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM