I want the version numbers of the Nuget package to be incremented and human readable with every version pushed to the Artifacts store. This is my yaml.
variables:
feedName : 'MyNugets'
buildConfiguration: 'release'
name: $(Year:yyyy).$(Month).$(DayOfMonth).$(Rev:.r)
pool:
vmImage: windows-latest
steps:
- task: DotNetCoreCLI#2
displayName: 'Build'
inputs:
command: 'build'
projects: '**/*.csproj'
arguments: '--configuration $(buildConfiguration)'
- task: DotNetCoreCLI#2
displayName: 'Pack'
inputs:
command: pack
versioningScheme: byBuildNumber
- task: NuGetAuthenticate#1
displayName: 'NuGet Authenticate'
- task: NuGetCommand#2
displayName: 'NuGet push'
inputs:
command: push
publishVstsFeed: '$(feedName)'
allowPackageConflicts: true
Whatever suggestion I could find on SO or other google result. None of them seems to be working. I always get this error.
##[error]Could not find version number data in the following environment variable: BUILD_BUILDNUMBER. The value of the variable should contain a substring with the following formats: X.Y.Z or X.Y.Z.A where A, X, Y, and Z are positive integers.
Any suggestions ?
Don't store the name in a variable, put in in a separate section above variables.
name: $(Year:yyyy).$(Month).$(DayOfMonth).$(Rev:.r)
variables:
feedName : 'MyNugets'
buildConfiguration: 'release'
See: https://learn.microsoft.com/en-us/azure/devops/pipelines/process/run-number?view=azure-devops&tabs=yaml
Related
I have an Azure DevOps Build (yaml) and Release Pipeline (Classic) successfully deploying to Azure.
I am trying to convert these 2 separate steps in a Multi Stage Yaml Pipeline.
On the Azure App Service Deploy task (AzureRmWebAppDeployment#4), I am getting the following error:
No package found with specified pattern: /home/vsts/work/1/a/*.zip
Below is my Multi Stage Yaml Pipeline
stages:
- stage: Build
jobs:
- job: 'Build'
pool:
vmImage: 'windows-latest'
variables:
buildConfiguration: 'Release'
steps:
- task: DotNetCoreCLI#2
displayName: Restore
inputs:
command: restore
projects: '**/*.csproj'
vstsFeed: 'dd55642d-8943-411f-8856-9714dd0da8af'
- task: DotNetCoreCLI#2
displayName: Build
inputs:
projects: '**/*.csproj'
arguments: '--configuration $(buildConfiguration)'
- task: DotNetCoreCLI#2
displayName: Test
inputs:
command: test
projects: '**/*[Tt]ests/*.csproj'
arguments: '--configuration $(buildConfiguration)'
- task: DotNetCoreCLI#2
displayName: Publish
inputs:
command: publish
publishWebProjects: false
projects: '**/Tools.Client.Blazor.ServerApp.csproj'
arguments: '--configuration $(buildConfiguration) --output $(build.artifactstagingdirectory)'
- task: PublishSymbols#2
displayName: 'Publish symbols path'
inputs:
SearchPattern: '**\bin\**\*.pdb'
PublishSymbols: false
continueOnError: true
- task: CopyFiles#2
displayName: 'Copy Files to: $(build.artifactstagingdirectory)\AzureDeploy'
inputs:
SourceFolder: AzureDeploy
TargetFolder: '$(build.artifactstagingdirectory)\AzureDeploy'
- task: PublishBuildArtifacts#1
displayName: 'Publish Artifact: drop'
inputs:
PathtoPublish: '$(build.artifactstagingdirectory)'
condition: succeededOrFailed()
- stage: Systest
jobs:
- job: 'Systest'
variables:
resourceGroupName: '$(appName)-rg-$(environment)'
location: 'East US'
appServiceName: '$(appName)-svc-$(environment)'
appInsightsName: '$(appName)-ins-$(environment)'
appServicePlanName: '$(appName)-asp-$(environment)'
appName: 'tools'
owner: 'Pod'
environment: 'systest'
steps:
- task: AzureResourceManagerTemplateDeployment#3
displayName: 'ARM Template deployment: Resource Group scope'
inputs:
azureResourceManagerConnection: 'Dev/Test Connection'
subscriptionId: ''
resourceGroupName: '$(resourceGroupName)'
location: '$(location)'
csmFile: '$(System.DefaultWorkingDirectory)/AzureDeploy/Tools.azureDeploy.json'
csmParametersFile: '$(System.DefaultWorkingDirectory)/AzureDeploy/Tools.azureDeploy.parameter.json'
overrideParameters: '-appServiceName "$(appServiceName)" -appInsightsName "$(appInsightsName)" -appServicePlanName "$(appServicePlanName)" -owner "$(owner)" -environment "$(environment)" -location "$(location)"'
- task: AzureRmWebAppDeployment#4
displayName: 'Azure App Service Deploy: $(appServiceName)'
inputs:
ConnectionType: 'AzureRM'
azureSubscription: ''
appType: 'webApp'
WebAppName: '$(appServiceName)'
packageForLinux: '$(Build.ArtifactStagingDirectory)/*.zip'
Any help / suggestions would be appreciated.
Because it's 2 stages the second stage doesn't have the file you published in the first stage, you need to download it.
You can use Pipeline artifacts instead of build artifacts.
Pipeline artifacts provide a way to share files between stages in a
pipeline or between different pipelines. They are typically the output
of a build process that needs to be consumed by another job or be
deployed. Artifacts are associated with the run they were produced in
and remain available after the run has completed.
To publish (upload) an artifact for the current run:
steps:
- publish: $(build.artifactstagingdirectory)
artifact: drop
And in the second stage, you download the artifact:
steps:
- download: current
artifact: drop
You can also achieve it with build artifacts and download with DownloadBuildArtifacts#0 task.
During Publish it will not work like this. Instead of using path "/home/vsts/work/1/a/.zip", this path can be used "$(System.DefaultWorkingDirectory)/_Releasepipelinename/drop/.zip"
So I've been doing some learning into Azure DevOps Yaml Pipelines and I've come across an issue I can't seem to figure out what would be the cause.
I was building my first pipeline for a small class library solution, the idea being to restore, build, test, pack & publish it when changes are committed into master.
I split the different parts of the deployment into stages/jobs (which may not be the correct way to use these), but when I do so, the "Nuget pack" step can never find any of the built files.
This YAML does not work, and errors out on the "NuGet (Pack)" Step because it cannot find the "projects.assets.json" file, which I have confirmed that the build step does produce.
trigger:
- master
pool:
vmImage: 'windows-latest'
name: 'Set dynamically'
variables:
buildConfiguration: 'Release'
version.Major: 1
version.Minor: $[counter(variables['version.Major'], 0)]
version.Patch: 0
version.Revision: $[counter(variables['version.Minor'], 0)]
version.Number: '$(version.Major).$(version.Minor).$(version.Patch).$(version.Revision)'
stages:
- stage: Prepare
jobs:
- job: Prepare_Sources
steps:
- checkout: self
clean: true
- job: Prepare_BuildAndVersionNumbers
steps:
- task: PowerShell#2
displayName: Set the name of the build
inputs:
targetType: 'inline'
script: |
[string] $dateTime = (Get-Date -Format 'yyyyMMdd')
[string] $buildName = "$(Build.DefinitionName)_$(Build.SourceBranchName)_$($dateTime)_$(version.Number)"
Write-Host "Setting the name of the build to '$buildName'."
Write-Host "##vso[build.updatebuildnumber]$buildName"
- stage: Build
jobs:
- job: BuildRestore
steps:
- task: NuGetCommand#2
displayName: 'Restore (NuGet)'
inputs:
command: restore
restoreSolution: '**\*.sln'fs
feedsToUse: select
includeNuGetOrg: true
vstsFeed: 'internalfeed1'
arguments: '--configuration $(buildConfiguration) /p:Version=$(version.Number)'
- task: DotNetCoreCLI#2
displayName: 'Restore (.NET Core)'
inputs:
command: restore
includeNuGetOrg: true
nobuild: true
vstsFeed: 'internalfeed1'
nuGetFeedType: internal
projects: '**/*.csproj'
arguments: '--configuration $(buildConfiguration) /p:Version=$(version.Number)'
- task: DotNetCoreCLI#2
displayName: 'Build all projects in solution'
inputs:
command: build
projects: '**/*.csproj'
arguments: '--configuration $(buildConfiguration) /p:Version=$(version.Number)'
- stage: Test
jobs:
- job: Test_UnitTests
steps:
- task: DotNetCoreCLI#2
displayName: 'Run & Analyse UnitTests'
inputs:
command: test
projects: '**/*Tests/*UnitTests.csproj'
arguments: '--configuration $(buildConfiguration) --collect "Code coverage"'
- stage: Package
jobs:
- job: Package_Nuget
steps:
- task: NuGetAuthenticate#0
displayName: "Nuget (Authenticate)"
- task: DotNetCoreCLI#2
displayName: 'NuGet (Package)'
inputs:
nobuild: true
command: pack
packagesToPack: '**/*.csproj'
versioningScheme: byBuildNumber
arguments: '--configuration $(buildConfiguration)'
- task: DotNetCoreCLI#2
displayName: 'NuGet (Publish)'
inputs:
command: push
searchPatternPush: '$(Build.ArtifactStagingDirectory)/*.nupkg;'
feedPublish: 'internalfeed1'
If I simplify it all down into one single job without the stages/jobs the deployment all works ok (as below)
trigger:
- master
pool:
vmImage: 'windows-latest'
name: 'Set dynamically'
variables:
buildConfiguration: 'Release'
version.Major: 1
version.Minor: $[counter(variables['version.Major'], 0)]
version.Patch: 0
version.Revision: $[counter(variables['version.Minor'], 0)]
version.Number: '$(version.Major).$(version.Minor).$(version.Patch).$(version.Revision)'
steps:
- checkout: self
clean: true
- task: PowerShell#2
displayName: Set the name of the build
inputs:
targetType: 'inline'
script: |
[string] $dateTime = (Get-Date -Format 'yyyyMMdd')
[string] $buildName = "$(Build.DefinitionName)_$(Build.SourceBranchName)_$($dateTime)_$(version.Number)"
Write-Host "Setting the name of the build to '$buildName'."
Write-Host "##vso[build.updatebuildnumber]$buildName"
- task: NuGetCommand#2
displayName: 'Restore (NuGet)'
inputs:
command: restore
restoreSolution: '**\*.sln'fs
feedsToUse: select
includeNuGetOrg: true
vstsFeed: 'internalfeed1'
arguments: '--configuration $(buildConfiguration) /p:Version=$(version.Number)'
- task: DotNetCoreCLI#2
displayName: 'Restore (.NET Core)'
inputs:
command: restore
includeNuGetOrg: true
nobuild: true
vstsFeed: 'internalfeed1'
nuGetFeedType: internal
projects: '**/*.csproj'
arguments: '--configuration $(buildConfiguration) /p:Version=$(version.Number)'
- task: DotNetCoreCLI#2
displayName: 'Build all projects in solution'
inputs:
command: build
projects: '**/*.csproj'
arguments: '--configuration $(buildConfiguration) /p:Version=$(version.Number)'
- task: DotNetCoreCLI#2
displayName: 'Run & Analyse UnitTests'
inputs:
command: test
projects: '**/*Tests/*UnitTests.csproj'
arguments: '--configuration $(buildConfiguration) --collect "Code coverage"'
- task: DotNetCoreCLI#2
displayName: 'NuGet (Package)'
inputs:
nobuild: true
command: pack
packagesToPack: '**/*.csproj'
versioningScheme: byBuildNumber
arguments: '--configuration $(buildConfiguration)'
- task: DotNetCoreCLI#2
displayName: 'NuGet (Publish)'
inputs:
command: push
searchPatternPush: '$(Build.ArtifactStagingDirectory)/*.nupkg;'
feedPublish: 'internalfeed1'
Can't find an answer on the documentation for these pieces of the puzzle that would explain why it wouldn't work when split up into stages/jobs, does anyone know what the reasoning is? Are Stages/Jobs not supposed to interact with each other in this way?
Thanks
This is becuase each job runs on different agent
A stage contains one or more jobs. Each job runs on an agent. A job represents an execution boundary of a set of steps. All of the steps run together on the same agent. For example, you might build two configurations - x86 and x64. In this case, you have one build stage and two jobs.
And this since jon is a boundary for set of steps source code is not shared amongs them. SO if you need keep this as seprate jobs and stages you should repeat in each job checkout step
- checkout: self
clean: true
Please read this basics about pipeline, they will give you high level picture how it works.
And if you want to share some artifact between jobs please take a look here.
And if you need share some variables between stages I wrote an article about this.
I am using Azure Devops YAML build pipeline for the build and test of my SQL SSDT project. I am trying to amend my YAML code so that the test part will run on multiple Microsoft hosted agents (I have purchased 2). When I run the VSTest task as part of the first job that is run on the single agent, it runs no problems. However, when I run it as part of the second job, the unit tests do not run, with an error saying it cannot find the requisite test files. Is there something I need to add to my second job to make this work?
Many thanks.
trigger:
branches:
include:
- develop
- stage
- master
pr:
- master
- stage
- develop
pool:
vmImage: 'windows-latest'
variables:
solution: '**/*.sln'
buildPlatform: 'Any CPU'
buildConfiguration: 'Release'
jobs:
- job: BuildPublish
steps:
- task: NuGetToolInstaller#1
inputs:
versionSpec: '2.*'
- task: NuGetCommand#2
inputs:
command: 'restore'
restoreSolution: '$(solution)'
feedsToUse: 'select'
restoreDirectory: '$(Build.SourcesDirectory)/DIP_UsqlSln/packages'
- task: VSBuild#1
inputs:
solution: '**/*.sln'
msbuildArgs: '/p:USQLSDKPath=$(Build.SourcesDirectory)/DIP_UsqlSln/packages/Microsoft.Azure.DataLake.USQL.SDK.1.4.190703/build/runtime;USQLTargetType=SyntaxCheck;DataRoot=$(Build.SourcesDirectory) /p:EnableDeployment=true'## Heading ##
createLogFile: true
logFileVerbosity: 'detailed'
- task: CopyFiles#2
inputs:
Contents: '**'
TargetFolder: '$(build.artifactstagingdirectory)'
CleanTargetFolder: true
OverWrite: true
- task: PublishBuildArtifacts#1
inputs:
PathtoPublish: '$(Build.ArtifactStagingDirectory)'
ArtifactName: 'drop'
publishLocation: 'Container'
- job: Test
dependsOn: BuildPublish
strategy:
parallel: 2
steps:
- task: DownloadBuildArtifacts#0
displayName: 'Download Build Artifacts'
inputs:
artifactName: 'drop'
- task: VSTest#2
inputs:
platform: '$(buildPlatform)'
configuration: '$(buildConfiguration)'
runOnlyImpactedTests: true
runInParallel: true
How to find unit test dll in Azure Devops when copying test artifact to run on multiple agents (YAML)
That because the default Destination directory for the task DownloadBuildArtifacts is $(System.ArtifactsDirectory), however, the default Search folder for Visual Studio Test task is $(System.DefaultWorkingDirectory).
When you use the those two task in the build pipeline, the value of those two predefined variables are not same:
The value of $(System.ArtifactsDirectory) should be C:\agent\_work\r1\a.
The value of $(System.DefaultWorkingDirectory) should be c:\agent_work\1\s.
So, it will cause this issue, could not found the requisite test files.
To resolve this issue, we just need to change the default value of those two predefined variables to use same value:
- task: DownloadBuildArtifacts#0
displayName: 'Download Build Artifacts'
inputs:
artifactName: drop
downloadPath: '$(System.DefaultWorkingDirectory)'
Or
- task: VSTest#2
inputs:
platform: '$(buildPlatform)'
configuration: '$(buildConfiguration)'
searchFolder: '$(System.ArtifactsDirectory)'
runOnlyImpactedTests: true
runInParallel: true
Hope this helps.
I am using Azure DevOps to Build and deploy my Azure Synapse
I have two YAML files. First one works well and I need to separate Build and Release steps. because of that I wrote second YAML file. Second YAML file has this error :
##[error]No files were found to deploy with search pattern
d:\a\1\s\SQL_ASynapse\bin\Release\SQL_ASynapse.dacpacCheck out how to troubleshoot failures at
https://aka.ms/sqlazuredeployreadme#troubleshooting-
First YAML file that works well:
trigger:
- master
pool:
vmImage: 'windows-latest'
variables:
solution: '**/*.sln'
buildPlatform: 'Any CPU'
buildConfiguration: 'Release'
steps:
- task: NuGetToolInstaller#1
- task: NuGetCommand#2
inputs:
restoreSolution: '$(solution)'
- task: AzureKeyVault#1
inputs:
azureSubscription: 'XXX'
KeyVaultName: 'XXX-Dev'
SecretsFilter: '*'
- task: VSBuild#1
inputs:
solution: '$(solution)'
platform: '$(buildPlatform)'
configuration: '$(buildConfiguration)'
- task: VSTest#2
inputs:
platform: '$(buildPlatform)'
configuration: '$(buildConfiguration)'
- task: SqlAzureDataWarehouseDacpacDeployment#1
inputs:
azureSubscription: 'XXX'
AuthenticationType: 'server'
ServerName: 'XXX'
DataWarehouse: '$(SynapseName)'
SqlUsername: '$(SynapseSQLUsername)'
SqlPassword: '$(SynapseSQLPassword)'
deployType: 'DacpacTask'
DeploymentAction: 'Publish'
DacpacFile: 'SQL_ASynapse\bin\Release\SQL_ASynapse.dacpac'
IpDetectionMethod: 'AutoDetect'
Second YAML file who has error:
trigger:
- master
variables:
solution: '**/*.sln'
buildPlatform: 'Any CPU'
buildConfiguration: 'Release'
# Agent VM image name
vmImageName: 'windows-latest'
stages:
- stage: Build
displayName: Build stage
jobs:
- job: Build
displayName: Build
pool:
vmImage: $(vmImageName)
steps:
- task: NuGetToolInstaller#1
- task: NuGetCommand#2
inputs:
restoreSolution: '$(solution)'
- task: VSBuild#1
inputs:
solution: '$(solution)'
platform: '$(buildPlatform)'
configuration: '$(buildConfiguration)'
- task: VSTest#2
inputs:
platform: '$(buildPlatform)'
configuration: '$(buildConfiguration)'
- stage: Deploy
displayName: Deploy stage
dependsOn: Build
condition: succeeded()
jobs:
- deployment: Deploy
displayName: Deploy
environment: 'development'
pool:
vmImage: $(vmImageName)
strategy:
runOnce:
deploy:
steps:
- task: AzureKeyVault#1
inputs:
azureSubscription: 'XXX-Dev'
KeyVaultName: 'XXX-Dev'
SecretsFilter: '*'
- task: SqlAzureDataWarehouseDacpacDeployment#1
inputs:
azureSubscription: 'XXX-Dev'
AuthenticationType: 'server'
ServerName: 'XXX'
DataWarehouse: '$(SynapseName)'
SqlUsername: '$(SynapseSQLUsername)'
SqlPassword: '$(SynapseSQLPassword)'
deployType: 'DacpacTask'
DeploymentAction: 'Publish'
DacpacFile: 'SQL_ASynapse\bin\Release\SQL_ASynapse.dacpac'
IpDetectionMethod: 'AutoDetect'
UPDATE #1 FOR #Levi Lu-MSFT ANSWER
I have changed my second script like below code :
...
- task: VSBuild#1
inputs:
solution: '$(solution)'
platform: '$(buildPlatform)'
configuration: '$(buildConfiguration)'
- publish: $(system.defaultworkingdirectory)\SQL_ASynapse\bin\Release ## path to a file or folder
artifact: MyBuildOutputs
...
- download: current # refers to artifacts published by current pipeline
artifact: MyBuildOutputs
- task: SqlAzureDataWarehouseDacpacDeployment#1
inputs:
azureSubscription: 'xxx-Dev'
AuthenticationType: 'server'
ServerName: 'xxx.database.windows.net'
DataWarehouse: '$(SynapseName)'
SqlUsername: '$(SynapseSQLUsername)'
SqlPassword: '$(SynapseSQLPassword)'
deployType: 'DacpacTask'
DeploymentAction: 'Publish'
DacpacFile: 'SQL_ASynapse\bin\Release\SQL_ASynapse.dacpac'
IpDetectionMethod: 'AutoDetect'
But I have still same error.
Upload task result
Download task result
SqlAzureDataWarehouseDacpacDeployment error :
##[error]No files were found to deploy with search pattern
d:\a\1\s\SQL_ASynapse\bin\Release\SQL_ASynapse.dacpacCheck out how to
troubleshoot failures at https://aka.ms/sqlazuredeployreadme#troubleshooting-
If you use Microsoft-hosted agent. Every job defined in the yaml pipeline will run on a fresh new virtual machine. The virtual machine is discarded after one use.
So that the build artifacts from Build job of Build stage doesnot exist on the agent machine of the deploy job of Deploy stage. That's why you got above error.
You need to add a publish task after Vsbuild task in Build job to publish the build results to azure devops server. You should specify the correct path(where the build artifacts reside) to publish.
- publish: $(system.defaultworkingdirectory)\SQL_ASynapse\bin\Release ## path to a file or folder
artifact: MyBuildOutputs
Then add a download task before qlAzureDataWarehouseDacpacDeployment task in Deploy job to download the build results to deploy job agent. So that the build results will be available to the deployment tasks.
- download: current # refers to artifacts published by current pipeline
artifact: MyBuildOutputs
To publish and download build artifacts, You can also use Publish Build Artifacts task, Download Build Artifacts task.
Update:
When you use download task: See here for more information.
By default, files are downloaded to $(Pipeline.Workspace)/{artifact}, where artifact is the name of the artifact. The folder structure of the artifact is always preserved.
And you can see from above updated screenshot. The artifacts is downloaded to folder D:\a\1\MyBuildOutputs
So you should set DacpacFile attribute as below:
DacpacFile : $(Pipeline.Workspace)/MyBuildOutputs/SQL_ASynapse.dacpac
The ambiguous call happens between Assert.Throws(Action)' and 'Assert.Throws(Func) anytime we pass a local function that throws an exception to Assert.Throws.
The error does not occur locally, but does when we run the build pipe line.
Able to repo with:
void iut() => throw new NotImplementedException();
Assert<NotImplentedException>(iut);
And the following yaml for a pipeline:
trigger:
- master
pool:
vmImage: 'Ubuntu-16.04'
variables:
buildConfiguration: 'Release'
steps:
- task: DotNetCoreCLI#2
displayName: 'dotnet restore'
inputs:
command: restore
projects: '**/*.csproj'
- task: DotNetCoreCLI#2
displayName: 'dotnet build'
inputs:
projects: '**/*.csproj'
- task: DotNetCoreCLI#2
displayName: 'dotnet test'
inputs:
command: test
projects: '**/*.Tests.csproj'
- task: PublishBuildArtifacts#1
displayName: 'Publish Artifact: drop'