【问题标题】:Setting up Build Pipeline for Azure Bot Service/Azure Functions solution in VSTS Build在 VSTS Build 中为 Azure Bot Service/Azure Functions 解决方案设置构建管道
【发布时间】:2016-12-14 12:01:15
【问题描述】:

我有一个 Azure 机器人服务解决方案,位于我的 VSTS Git 存储库中。

我在 Visual Studio 中使用 Task Runner 在我的本地机器上编译、运行和调试代码。

同样,我想在我的 VSTS 构建管道中构建和编译代码,就像我们如何使用 Visual Studio 模板构建 .Net 应用程序一样

我对拥有 C# 脚本文件的 Bot 服务项目非常陌生。

我看到 msdn 文档都提到了持续集成,它将直接链接到我的 Git repo 分支。每当我提交代码时,它都会自动推送到我的 Azure Bot 服务,在这里我想确保我提交的代码应该在推送到 Azure Bot 服务之前进行编译。为此,我想设置一个构建管道。

谁能知道如何为这种具有 C# 脚本文件的项目设置构建管道?

更新:

在我的本地 PC 中,我安装了 Azure Functions CLI 工具和 Visual Studio 的 Command Task Runner 扩展。我按照以下链接在本地启用调试 enter link description here

运行我的机器人服务代码中的 debughost.cmd 文件的任务运行程序,它包含以下代码

    @echo off
set size=0
call func settings list -data > %temp%\settings-list
call :filesize %temp%\settings-list
if NOT %size% == 0 goto show
@echo ----------------------------------------------------------------------
@echo To fetch your bot service settings run the following command:
@echo     func azure functionapp fetch-app-settings [YOUR_BOT_SERVICE_NAME]
@echo func azure functionapp fetch-app-settings AthenaDevbvpn6xsu2tz6i
@echo ----------------------------------------------------------------------

goto start

:show
type %temp%\settings-list
erase %temp%\settings-list 

:start
@func host start -p 3978 
goto :eof

:filesize
  set size=%~z1
  exit /b 0

任务运行器的输出是

【问题讨论】:

  • 如何在本地编译项目?比如 Gulp、Grunt 等……
  • @starain-MSFT 我更新了我的问题,提供了更多关于我如何在本地调试的信息。您能否指导我如何在构建步骤中进行调试?
  • 我做了一个测试,构建过程会一直在运行 debughost.cmd (命令行步骤),无法完成,无法调试。
  • @starain-MSFT 有没有其他方法可以在 VSTS 构建中构建此类项目?如果有任何帮助的例子。
  • @narendramacha 该构建用于构建您的代码并将构建输出发布到某个地方进行测试或部署。为什么要从 VSTS 构建中调试它?

标签: azure-devops azure-functions azure-pipelines azure-pipelines-build-task azure-bot-service


【解决方案1】:

目前没有任何现成的任务来编译 CSX 文件。以下是我可以为您的场景考虑的解决方法,但并不完美:

  1. Deploy your own build agent,然后按照您提供的链接中的步骤进行配置:Debugging C# bots built using the Azure Bot Service on Windows
  2. 创建一个 powershell 脚本来调用 Azure Function CLI 来编译 csx 文件,就像“debughost.cmd”所做的那样,并检查编译过程中是否出现任何错误。
  3. 将 powershell 脚本上传到源代码管理中。
  4. 在您的构建定义中添加一个 powershell 脚本任务以调用您创建的 powershell 脚本。
  5. 保存构建定义并将其排队。

这是我创建的 powershell 脚本供您参考:

##Run Azure Func command to compile csx file
$compile = Start-Process 'func' -passthru -WorkingDirectory '.' -ArgumentList 'host start -p 3739' -RedirectStandardOutput 'output.txt'
##You need to set the sleep time base on the build time of your project
Start-Sleep -s 20
Stop-Process $compile -Force
Stop-Process -Name 'Func'

##Get the output from Func and check if there is error in the output
$boutput = Get-Content 'output.txt'
Write-Host 'Azure Function CLI Log:'
Write-Host '*****************************************************************************************************************************'
$boutput
Write-Host '*****************************************************************************************************************************'

$reg = "Function.compilation.error"
foreach($line in $boutput){
    if($line -match $reg)
    {
        ##Fail the task if function compilation error exist
        Write-Host '##vso[task.logissue type=error]Error occur during function compilation'
        Exit 1
    }
 }
 Write-Host 'Function compilation success!'

如果编译失败,你会得到这个结果:

【讨论】:

  • 是的,我目前正在做类似的事情。但是你的剧本比我的好。谢谢。
【解决方案2】:

对于 Azure Bot Service,在 VSTS 中设置与存储库的 master 分支的持续集成,对于 VSTS 中的存储库,您可以创建一个新分支,例如 Dev,然后使用 Dev 分支并合并到 master。之后代码将更新为 azure。

简单步骤:

  1. 在 VSTS 中将持续集成设置到您的存储库(主分支)
  2. 在 VSTS 中转到存储库的代码页面
  3. 选择分支
  4. 点击新建分支(例如 dev)
  5. 将 dev 分支克隆到本地并使用它(例如修改)
  6. 将更改推送到远程 Dev 分支
  7. 创建构建定义
  8. 在选项选项卡中启用允许脚本访问 OAuth 令牌选项。
  9. 根据您在本地的构建方式添加构建应用程序的步骤(例如 gulp)
  10. 添加命令行步骤

  1. 添加命令行步骤

  1. 添加命令行步骤

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-08-03
    • 1970-01-01
    • 2020-06-29
    • 2021-06-03
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多