Setting up Build Pipeline for Azure Bot Service/Azure Functions solution in VSTS Build

442 views Asked by At

I have an Azure bot service solution, which is in my VSTS Git repository.

enter image description here

I am using Task Runner in visual studio to compile, run and debug code on my local machine.

Similarly, I want to build and compile the code in my VSTS build pipeline, like how we do build using Visual Studio template for .Net applications

enter image description here

I am very new to Bot service projects where it having C# Script files.

I have seen msdn documents all are mentioned Continuous Integration where it will directly link to my Git repo branch. Whenever I commit code it automatically push to My Azure Bot Service, here I want to make sure the code I commit should be compile before push to Azure Bot service. For that I want to setup a Build pipeline.

Can anyone know how to setup a build pipeline for this kind of projects which having C# Script files?

UPDATE:

In my local PC I have installed Azure Functions CLI tools, and Command Task Runner extension to visual studio. I followed the below link to enable debugging locally enter link description here

Task runner running debughost.cmd file which is in my Bot Service code, it contains the following code

    @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

Output in task runner is

enter image description here

2

There are 2 answers

1
Eddie Chen - MSFT On BEST ANSWER

There isn't any out of box task to compile CSX file for now. Following is the workaround I can think for your scenario but which is not perfect:

  1. Deploy your own build agent and then configure it by following the steps in the link you provided: Debugging C# bots built using the Azure Bot Service on Windows.
  2. Create a powershell script to call the Azure Function CLI to compile the csx file like the "debughost.cmd" did and check if there is any error occur during the compilation.
  3. Upload the powershell script into the source control.
  4. Add a powershell script task in your build definition to call the powershell script you created.
  5. Save and queue the build definition.

Here is the powershell script I created for your reference:

##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!'

And you will get this result if the compilation failed: enter image description here

0
starian chen-MSFT On

For Azure Bot Service, set continuous integration with master branch of your repository in VSTS, for repository in VSTS, you can create a new branch, such as Dev, then do work with Dev branch and merge to master. After that the code will be updated to azure.

Simple Steps:

  1. Set continuous integration to your repository (master branch) in VSTS
  2. Go to Code page of your repository in VSTS
  3. Select Branches
  4. Click New branch (e.g. dev)
  5. Clone dev branch to your local and work with it (e.g. modify)
  6. Push changes to remote Dev branch
  7. Create a build definition
  8. Enable Allow Scripts to Access OAuth Token option in Options tab. enter image description here
  9. Add a step to build app (e.g. gulp) according how do you build in local
  10. Add Command Line step

enter image description here

  1. Add Command Line step

enter image description here

  1. Add Command Line step

enter image description here