How to configure Azure CI/CD to update latest changes - azure

I am currently developing a chatbot using the azure bot service framework and am having difficulty understanding how to get the latest changes published to the web chat once the pipeline has completed.
I configured the pipeline through azure and pointed it at my repo and master branch, but for some reason when the pipeline has completed the web chat doesn't get updated even though the pipeline includes a publish step.
Is there a setting I am missing in order to get the web chat to update automatically?
Thanks

You can follow the steps below to configure CI/CD.
In Pipeline CI , you could set the master branch as trigger . In this caseļ¼Œ when the master branch changes, Build will be triggered.
You could add build step and publish artifacts steps in CI. Then the build will create an artifact which could be used in the CD(Release) step.
For example:
trigger:
- master
pool:
vmImage: 'windows-latest'
steps:
- task: NuGetCommand#2
displayName: 'NuGet restore'
inputs:
restoreSolution: 'application/*.sln'
- task: VSBuild#1
displayName: 'Build solution application/*.sln'
inputs:
solution: 'application/*.sln'
msbuildArgs: '/p:DeployOnBuild=true /p:WebPublishMethod=Package /p:PackageAsSingleFile=true /p:SkipInvalidConfigurations=true /p:PackageLocation="$(Build.ArtifactStagingDirectory)/package/$(Build.BuildId).zip"'
- task: PublishPipelineArtifact#0
inputs:
artifactName: 'applicationpackage'
targetPath: '$(Build.ArtifactStagingDirectory)/package'
In Release CD, you could set the CD trigger for the release and select the Build as the artifacts resource. If you need to use the ARM template, you also could add the resource repo as another artifacts.
When you set the CD trigger, the release will run after the build pipeline finishes.
You could add the release tasks in the Release Pipeline.(e.g. Azure resource group deployment, Azure App Service deploy)
Here is a official doc about Azure DevOps CI/CD pipelines for chatbots. You could refer to it.

Related

How to get a java jar file to publish to artifacts section in azure devops?

I want to publish a java jar file to azure devops artifacts section in azure devops. Once it is there, I want to be able to setup my gradle so it can download jars from that location. I think I understand how to do the second step, but how to do the first step is not clear to me. I can use an azure pipelines task to build the jar and publish the artifact. However the published artifact does not end up in the location I want. It ends up in an artifacts section of the pipeline run, it does not end up in the artifacts section of ADO. Here is the code:
steps:
- checkout: self
path: 'my-repo/'
- task: Gradle#2
displayName: Test and build jar
inputs:
gradleWrapperFile: 'gradlew'
tasks: 'build'
publishJUnitResults: false
javaHomeOption: 'JDKVersion'
- task: PublishBuildArtifacts#1
inputs:
pathToPublish: '$(System.DefaultWorkingDirectory)/build/libs/commons.jar'
You can see in this image. The green arrow points to where the artifact ends up after successful execution of the above code. However when I click on the artifacts section indicated by the blue arrow it is not there. How do I get it to publish over there so it can be consumed by my build process on my local machine? Thanks in advance.
PublishBuildArtifacts#1 publishes 'Build artifacts' which are later available to be downloaded by DownloadBuildArtifacts#0 in later pipeline stages or in another pipelines. (And it will be only accessible where your green arrow points)
'Build artifact' is not the same thing as 'Artifacts Feed'
'Artifacts Feed' serves as source of packages which can be downloaded for example by NuGet if you configure in nuget.exe as a source your 'Artifacts Feed'
For example you can add NuGet package there using NuGet push(with firstly configured Source)
https://learn.microsoft.com/en-us/azure/devops/artifacts/get-started-nuget?view=azure-devops&tabs=windows#publish-a-nuget-package-by-using-the-command-line
To publish Universal Packages there is already task UniversalPackages#0
https://learn.microsoft.com/en-us/azure/devops/pipelines/artifacts/universal-packages?toc=%2Fazure%2Fdevops%2Fartifacts%2Ftoc.json&bc=%2Fazure%2Fdevops%2Fartifacts%2Fbreadcrumb%2Ftoc.json&view=azure-devops&tabs=yaml

Azure CI/CD: On-Premise deployment failing

I am trying to deploy my code from Azure to my local machine. The steps I followed:
Created deployment group
Run register script on my machine(the folders successfully created in C:\azagent)
Created pipeline.
For pipeline the generated YAML is:
# ASP.NET
# Build and test ASP.NET projects.
# Add steps that publish symbols, save build artifacts, deploy, and more:
# https://learn.microsoft.com/azure/devops/pipelines/apps/aspnet/build-aspnet-4
trigger:
- master
pool:
vmImage: 'windows-latest'
variables:
solution: '**/*.sln'
buildPlatform: 'Any CPU'
buildConfiguration: 'Release'
steps:
- task: NuGetCommand#2
inputs:
command: 'restore'
restoreSolution: '**/*.sln'
feedsToUse: 'select'
vstsFeed: 'a31f9237-4431-41f2-b1a9-4370c7dc4828/a3a86133-79b3-437a-bc19-9665a420de4e'
- task: VSBuild#1
inputs:
solution: '**\*.sln'
msbuildArgs: '/p:DeployOnBuild=true /p:WebPublishMethod=Package /p:PackageAsSingleFile=true /p:SkipInvalidConfigurations=true /p:PackageLocation="$(build.artifactStagingDirectory)"'
platform: '$(buildPlatform)'
configuration: '$(buildConfiguration)'
restoreNugetPackages: true
- task: CopyFiles#2
inputs:
SourceFolder: '$(build.sourcesdirectory)'
Contents: '**\bin\$(BuildConfiguration)\**'
TargetFolder: '$(build.artifactstagingdirectory)'
CleanTargetFolder: true
OverWrite: true
- task: PublishBuildArtifacts#1
inputs:
PathtoPublish: '$(Build.ArtifactStagingDirectory)'
ArtifactName: 'drop'
publishLocation: 'Container'
When I run the pipeline, it doesn't give any error but in release part I get an error:
The solution I am using has multiple projects. I need to deploy three projects on my machine. This is the first time I am using Azure DevOps and I don't have any clue about the error. Online articles are mostly explaining about cloud deployment and I could not find much about on-premise. In short my requirement is to deploy three projects from my repo on my local machine whenever I push any changes to master branch. Is there any step by step guide to achieve the same? What is the step I missed in the setup? Any help is much appreciated.
According to the description of the error message, first you need to check whether the corresponding build pipeline is selected as the release artifact source.
Then you can check whether the download artifacts path is consistent with the file path to the package(Package or Folder) of the IIS web app deploy task.
System.DefaultWorkingDirectory : The directory to which artifacts are downloaded during deployment of a release. The directory is cleared before every deployment if it requires artifacts to be downloaded to the agent. Same as Agent.ReleaseDirectory and System.ArtifactsDirectory.
Example: C:\agent\_work\r1\a
For details, please refer to predefined variables document.
my requirement is to deploy three projects from my repo on my local
machine whenever I push any changes to master branch.Is there any step by step guide to achieve the same?
To achieve this , in yaml build pipeline ,you need to set CI trigger: Continuous integration (CI) triggers cause a pipeline to run whenever you push an update to the specified branches.
In release pipeline , you need to set build pipeline as release artifact source, and then enable Continuous deployment trigger: This instructs Azure Pipelines to create new releases automatically when it detects new artifacts are available.

WebJob cannot be added from portal if deployment form source control is configured

Today we experienced the following message in Azure Portal
WebJob cannot be added from portal if deployment form source control is configured.
We assume that this is a new feature hence the spelling is incorrect: 'deployment form source control' should be 'deployment from source control'.
I have no clue where to set a setting that solved this.
It has to be somewhere in DevOps we assume.
We solved it by not disconnecting a pipeline.
We solved it by implementing a seperate WebJob Build/Release Pipeline.
Here are the steps that worked for us:
In Azure Portal
Create a virtual application in your app service
In DevOps
In your build pipeline
Important Notice: add the following Argument: --output $(build.artifactstagingdirectory) to the build step.
In your release pipeline
This deploys the WebJob to the correct directory. In our case: $(System.DefaultWorkingDirectory)/_ms-reporting-webjob-dev-CI/drop
Having a look at the Kudo Console in our App Service the file location for our WebJob is:
Kudu Console
The workaround that worked for me was uploading the webjob directly via the Kudu Console.
Open the Kudu Console by selecting "Advanced Tool" --> "Go" in Your App Service on the Azure Portal.
Once on the Kudu portal open a "Debug Console" --> "CMD"
Go to the directory for your webjobs: "d:\home\site\wwwroot\app_data\jobs\continuous\{job name}" (https://github.com/projectkudu/kudu/wiki/WebJobs)
Then drag and drop the .zip file you prepared to upload your webjob (https://github.com/projectkudu/kudu/wiki/Kudu-console)
The job will now be listed on the Azure Portal and be started.
I used the following physical path in the Virtual Application and it solved it for us
site\wwwroot\App_Data\jobs\triggered\jobname
We had the same issue and noticed there was an old deployment pipeline connected to our web job in the Deployment Center blade. Disconnecting this solved the problem for us and we were able to manually deploy.
I used Kudu console to upload the webjobs
You can go to the path D:\home\site\wwwroot\App_Data\jobs\ and then upload the webjob folder here and then this shows up in your Webjobs portal as well
Don't go for the new CICD pipeline creation of this issue. Don't use chrome/safer while disconnecting the deployment center. Please use the latest IE or Microsoft Edge. it will allow the disconnect of the deployment center. I am able to do that in Microsoft Edge.
We had the same issue, and there was default configuration in deployment center for my web application, but we are not deploying the code from reposiotry, so we disabled that option. We are deploying web application from visual studio.
Currently the image showing disabled repository options in deployment center of the web application.
Probably because You set CI/CD for your web app deployment.
If you set your deployment with Azure Devops pipelines, and you are doing the yaml file approach, then maybe this is what you are looking for.
firstly you need to set the branch that you want to be triggred when a new commit has been pushed to it.
trigger:
branches:
include:
- refs/heads/staging
variables:
BuildConfiguration: 'Release'
pr: none # Disable pull request triggers.
To make our pipeline a little bit organized, We will work with stages, let's create our Build stage, here I am building a .Net app, you can replace the build task with the build you want.
stages:
- stage: 'Build'
jobs:
- job: 'Build'
pool:
vmImage: 'windows-latest' #The agent that will be used to start this stage
steps:
- task: DotNetCoreCLI#2
displayName: 'dotnet build'
inputs:
command: build
projects: 'MySuperApp/BackgroundService.csproj'
arguments: '--configuration $(BuildConfiguration)'
then I will run dotnet publish, that publishes the application and its dependencies to a folder for deployment to a hosting system.
and here comes the important part, when you create a webjob from azure portal, its files are stored under specific folder.
for Continuous webjobs, it will be stored under \site\wwwroot\app_data\Jobs\Continuous
and for Triggered webjobs it will be under \site\wwwroot\app_data\Jobs\Triggered
- task: DotNetCoreCLI#2
displayName: 'dotnet publish'
inputs:
command: 'publish'
arguments: '--configuration $(BuildConfiguration) --output $(Build.ArtifactStagingDirectory)/publish_output/App_Data/jobs/continuous/MySuperAppBGS'
projects: 'MySuperApp/BackgroundService.csproj'
publishWebProjects: false
zipAfterPublish: false
modifyOutputPath: false
for me I need to deploy a continuous webjob, as you can see in the arguments within inputs:
--output $(Build.ArtifactStagingDirectory)/publish_output/App_Data/jobs/continuous/MySuperAppBGS'
the dotnet publish will put the generated files under $(Build.ArtifactStagingDirectory)/publish_output/App_Data/jobs/continuous/MySuperAppBGS
then I will zip the content of $(Build.ArtifactStagingDirectory)/publish_output/ which is App_Data/jobs/continuous/MySuperAppBGS
- task: ArchiveFiles#2
displayName: 'Zip Published Files'
inputs:
rootFolderOrFile: '$(Build.ArtifactStagingDirectory)/publish_output'
includeRootFolder: false
archiveType: 'zip'
archiveFile: '$(Build.ArtifactStagingDirectory)/MySuperAppAPIBackgroundService.zip'
replaceExistingArchive: true
and publish the content of $(Build.ArtifactStagingDirectory) to drop artifact, which our zip file exist MySuperAppAPIBackgroundService.zip, in order to use it, in the next stage
- task: PublishBuildArtifacts#1
displayName: 'Publish Build artifacts'
inputs:
PathtoPublish: '$(Build.ArtifactStagingDirectory)'
ArtifactName: 'drop'
publishLocation: 'Container'
Here is the second stage, that will deploy our zip file to the web app service, then it will be unzipped leaving
App_Data/jobs/continuous/MySuperAppBGS/* under \site\wwwroot\
- stage: 'Deploy'
jobs:
- deployment: 'Deploy'
environment: 'MySuperAppAPI_BackGround_Staging_env' #just an env variable, that will be used later if you want, give it whatever name you like
strategy:
runOnce:
deploy:
steps:
- task: AzureWebApp#1
displayName: 'Deploy MySuperAppAPIBackgroundService.zip to MySuperAppAPI-Staging-BackgroundService'
inputs:
azureSubscription: 'Your Azure service connection'
appType: 'webApp'
appName: 'MySuperAppAPI-Staging-BackgroundService'
package: '$(Pipeline.Workspace)/drop/MySuperAppAPIBackgroundService.zip'
deploymentMethod: 'zipDeploy'
Note: in the second stage, I didn't call DownloadBuildArtifacts#0 task, because I used deploy: within - deployment: job that auto inject the Download artifact task, and to access the published Artifact from the previous stage, you use $(Pipeline.Workspace) following by the artifact name you provided, in my case it is $(Pipeline.Workspace)/drop
Hope I was clear, for any clarification don't hesitate to ask me.

Deploying a WebAPI project with several webjobs in Azure Devops

I am trying to use Azure Devops to do CI/CD. I have created the appropriate Git triggers to build when I push and I create a new release whenever I have produced a new build.
In the release tab I am trying to deploy a WebAPI project with several webjobs using the "Deploy Azure App Service" template. All the logs seem to indicate everything goes fine, but in the end I have nothing when I check the app service in Azure!
I have tried many different configurations and even a few more templates. They all seem fine according to the logs, but nothing is actually ever deployed!
If I try to build/deploy from VS2017 it works beautifully!
QUESTION
what do I need to do in order to successfully deploy my code via Azure Devops
.
My build YAML file is fairly close to the default, only added the CopyFiles#2 due to another SO post suggesting it:
trigger:
tags:
include:
- slot*
branches:
include:
- dev
pool:
vmImage: 'VS2017-Win2016'
variables:
solution: '**/*.sln'
buildPlatform: 'Any CPU'
buildConfiguration: 'Release'
name: $(SourceBranchName)_$(Date:yyyyMMdd)$(Rev:.r)
steps:
- task: NuGetToolInstaller#0
- task: NuGetCommand#2
inputs:
restoreSolution: '$(solution)'
- task: VSBuild#1
inputs:
solution: '$(solution)'
msbuildArgs: '/p:DeployOnBuild=true /p:WebPublishMethod=Package /p:PackageAsSingleFile=true /p:SkipInvalidConfigurations=true /p:PackageLocation="$(build.artifactStagingDirectory)"'
platform: '$(buildPlatform)'
configuration: '$(buildConfiguration)'
- task: CopyFiles#2
inputs:
targetFolder: '$(Build.ArtifactStagingDirectory)'
- task: PublishBuildArtifacts#1
condition: succeeded() #and(succeeded(), eq(variables['Build.SourceBranch'], 'refs/heads/master'))
- task: VSTest#2
inputs:
platform: '$(buildPlatform)'
configuration: '$(buildConfiguration)'
Second step I create a release from the artifacts produced via the YAML file.
Please add the following line in your package or folder option
$(System.DefaultWorkingDirectory)\*.*
It will make sure to pick all the files while deploying.
Also please refer to these ways to deploy webjob to azure:
Modify Visual Studio Build task to deploy webjob with FileSystem (MSBuild Arguments: /p:DeployOnBuild=true /p:WebPublishMethod=FileSystem /p:publishUrl="$(build.artifactstagingdirectory)\\WebJob" /p:DeployDefaultTarget=WebPublish)
Add Delete Files task to release definition to delete bin folder (Source Folder:
$(System.DefaultWorkingDirectory)/WebJobVnext/drop/WebJob); Contents:bin)
Modify Azure App Service Deploy task (
Uncheck Publish using Web Deploy option.
Package or folder: $(System.DefaultWorkingDirectory)/[artifact name]
/drop/WebJob)
Hope it helps.
There are two main problems with your deploy task.
As Mohit said, you need to specify the zip file of the web project you want to deploy, not just the directory it is in.
You need to uncheck "Exclude files from the App_Data folder". This will prevent webjobs from deploying with the website
2.1 If you haven't, in Visual Studio, you need to right click your web project Add > Existing Project as Azure Webjob. Do this for every webjob project so it will package the webjobs with the website

Azure Functions: how to deploy a project downloaded from the Azure portal?

I have implemented a C# function in the Azure Portal.
I downloaded the content of the Function App as a Visual Studio project.
I now want to deploy it with Azure DevOps release pipeline.
The deployment works fine but my function is not deployed. Sounds like the .csx file is not taken into account.
I tried to change the Build Action of the csx file to C# Compiler but it failed during the compilation with missing dependencies. Not sure it is the right way to proceed.
What are the steps to deploy the Azure functions?
It seems a little bit overkill to deploy csx functions with AzureDevOps. We could simply zip those files in the same folder structure as they were downloaded, go to https://<functionappname>.scm.azurewebsites.net/ZipDeployUI and drag the zip file to deploy. If you prefer command line instead of manual deployment, check Azure CLI command.
If you have to work with AzureDevOps, have a look at Build pipeline YAML below(Release pipeline is the default template Deploy a function app to Azure Functions).
resources:
- repo: self
queue:
name: Hosted VS2017
steps:
- task: ArchiveFiles#2
displayName: 'Archive $(system.defaultworkingdirectory)'
inputs:
rootFolderOrFile: '$(system.defaultworkingdirectory)'
includeRootFolder: false
- task: PublishBuildArtifacts#1
displayName: 'Publish Artifact: drop'
Note that the <functionName>.csproj file downloaded is useless and shouldn't be commited to repo. But if we have installed some extensions and see extensions.csproj file, add Net Core build task before ArchiveFiles#2.
- task: DotNetCoreCLI#2
displayName: Build
inputs:
projects: '$(Parameters.RestoreBuildProjects)'
arguments: '--configuration release -o bin --no-incremental'

Resources