在VSTS Build中为Azure Bot服务/ Azure功能解决方案设置构建管道

时间:2016-12-14 12:01:15

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

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

enter image description here

我在visual studio中使用Task Runner在我的本地计算机上编译,运行和调试代码。

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

enter image description here

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

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

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

更新

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

任务运行器运行debughost.cmd文件,它在我的Bot服务代码中,它包含以下代码

    @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

任务运行器中的输出是

enter image description here

2 个答案:

答案 0 :(得分:2)

现在没有任何开箱即用的任务来编译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. 保存并排队构建定义。
  6. 以下是我创建的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!'
    

    如果编译失败,您将得到此结果: enter image description here

答案 1 :(得分:1)

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

简单步骤:

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

    1. 添加命令行步骤
    2. enter image description here

      1. 添加命令行步骤
      2. enter image description here