Azure DevOps| Cache#2 - CACHE_RESTORED always evaluating to false - azure-devops

Why is CACHE_RESTORED always evaluating to false?
My solution has two projects. For both projects, I added property RestorePackagesWithLockFile set to true, I build the solution, then added the packages.lock.json files to source control. I've made a series of changes to where the caches should have been generated by now, however pipeline runs always say There is a cache miss.
Here are the relevant steps for the pipeline:
steps:
- task: NuGetToolInstaller#1
- task: Cache#2
inputs:
key: 'nuget | "$(Agent.OS)" | **/packages.lock.json,!**/bin/**,!**/obj/**'
restoreKeys: |
nuget | "$(Agent.OS)"
nuget
path: $(Pipeline.Workspace)/.nuget/packages
cacheHitVar: CACHE_RESTORED
- task: NuGetCommand#2
displayName: NuGet restore
condition: ne(variables.CACHE_RESTORED, true)
inputs:
command: restore
restoreSolution: ${{ parameters.solution }}
feedsToUse: select
vstsFeed: xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx...
Here is the output of the pipeline run:
Starting: Cache
==============================================================================
Task : Cache
Description : Cache files between runs
Version : 2.198.0
Author : Microsoft Corporation
Help : https://aka.ms/pipeline-caching-docs
==============================================================================
Resolving key:
- nuget [string]
- "Windows_NT" [string]
- **/packages.lock.json,!**/bin/**,!**/obj/** [file pattern; matches: 2]
- s\Project1\packages.lock.json --> 9999999999999999999999999999999999999999999999999999999999999999
- s\Project2\packages.lock.json --> 8888888888888888888888888888888888888888888888888888888888888888
Resolved to: nuget|"Windows_NT"|123456781234567812345678TxQePOdHp6IqQWh9w6w=
Resolving restore key:
- nuget [string]
- "Windows_NT" [string]
Resolved to: nuget|"Windows_NT"|**
Resolving restore key:
- nuget [string]
Resolved to: nuget|**
Using default max parallelism.
Max dedup parallelism: 192
ApplicationInsightsTelemetrySender will correlate events with X-TFS-Session xxxxxxx-xxxx-xxxx-xxxx-xxxxxxxx
Getting a pipeline cache artifact with one of the following fingerprints:
Fingerprint: `nuget|"Windows_NT"|123456781234567812345678TxQePOdHp6IqQWh9w6w=`
Fingerprint: `nuget|"Windows_NT"|**`
Fingerprint: `nuget|**`
There is a cache miss.
ApplicationInsightsTelemetrySender correlated 1 events with X-TFS-Session xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxx
Finishing: Cache
The fingerprint value 123456781234567812345678TxQePOdHp6IqQWh9w6w= (masked) is the same value in the previous two pipeline runs.
What am I missing?
Update:
the path $(Pipeline.Workspace)/.nuget/packages - this doesn't exist on a hosted agent. Need to find the right path?

Related

Azure Pipeline - DevOps19 + VS22: Building Solution with two different projects

This post will be a bit longer, as I not only describe my problem, but also show my different attempts to solve the problem.
I have a solution contaning .Net-6-Web-Api-Project (csproj) and a C++/CLI-Wrapper-Project (vcxproj). I have a reference from the C#-Project to the c++-Project. I use DevOps 2019 and VS22 on my local building agent.
I'm not able to successfully run this solution through an Azure DevOps Pipeline using the task DotNetCoreCLI#2, VSBuild#1 or a custom script as a workaround for the MSBuild#1 to publish.
VSBuild
My initial approach was to simply use the VSBuild#1 task. Using this task does not allow the pipeline to start, with the following error:
##[Error 1]
No agent found in pool My_Pool which satisfies the specified demands:
agent.name -equals My_Agend_Unity_1
Cmd
msbuild
visualstudio
Agent.Version -gtVersion 2.153.1
The cause is the compatibility issue between DevOps 2019 and VS2022. The agent does not recognize VS2022 and therefore does not create system capabilities for it. Its the same issue for the MSBuild#1 and why I tried a custom script to work around, because it couldn't find MSBuild.
DotNetCoreCLI
The first error I got was:
error MSB4019: The imported project "C:\Microsoft.Cpp.Default.props" was not found. Confirm that the expression in the Import declaration "\Microsoft.Cpp.Default.props" is correct, and that the file exists on disk.
So I fixed that by adding the env variable to the task:
env:
PATH: 'C:\Program Files\Microsoft Visual Studio\2022\Community\MSBuild\Microsoft\VC\v170'
The resulting further error was:
##[error]Error: Unable to locate executable file: 'dotnet'. Please verify either the file path exists or the file can be found within a directory specified by the PATH environment variable. Also verify the file has a valid extension for an executable file.
So I tried to fix it by using the Task UseDotNet#2, even though it doesn't make sense to me. But at the end I still get an error similar to the first error.:
MSBuild version 17.3.2+561848881 for .NET
C:\agent\_work\2\s\XXX\YYY\CPPWrapper\MyProject.vcxproj : warning NU1503: Skipping restore for project "C:\agent\_work\2\s\XXX\YYY\CPPWrapper\MyProject.vcxproj". The project file may be invalid or missing targets required for restore. [C:\agent\_work\2\s\XXX\YYY\MySolution.sln]
Determining projects to restore...
"C:\agent\_work\2\s\XXX\YYY\DotNet6Project\MyProject.csproj" restored (in "2,4 sec").
C:\agent\_work\2\s\XXX\YYY\CPPWrapper\MyProject.vcxproj(21,3):error MSB4019: The imported project "C:\Microsoft.Cpp.Default.props" was not found. Confirm that the expression in the Import declaration "\Microsoft.Cpp.Default.props" is correct, and that the file exists on disk.
C:\agent\_work\2\s\XXX\YYY\CPPWrapper\MyProject.vcxproj(21,3): error MSB4019: The imported project "C:\Microsoft.Cpp.Default.props" was not found. Confirm that the expression in the Import declaration "\Microsoft.Cpp.Default.props" is correct, and that the file exists on disk.
##[error]Error: The process 'C:\agent\_work\_tool\dotnet\dotnet.exe' failed with exit code 1
##[error]Dotnet command failed with non-zero exit code on the following projects : C:\agent\_work\2\s\XXX\YYY\MySolution.sln
##[section]Finishing: Build & Publish XXX Service - DotNetCoreCLI#2
MSBuild
My last hope then was my custom script that I already use in another pipeline that accesses the same agent and uses MSBuild from VS22. This is the approach I've come furthest with, as it looks like the project builds fine, but then fails because of this error.
(ResolvePackageAssets Target) -> C:\Program Files\dotnet\sdk\7.0.101\Sdks\Microsoft.NET.Sdk\targets\Microsoft.PackageDependencyResolution.targets(267,5):
error NETSDK1064: Package "Microsoft.EntityFrameworkCore.Analyzers",
Version 6.0.4, not found. It may have been deleted after the NuGet restore.
Otherwise, the NuGet restore may have been only partially completed due to limitations on the maximum path length.
[C:\agent\_work\2\s\XXX\YYY\DotNet6Project\MyProject.csproj]
How to proceed with it, I do not know right now. I enabled already long paths via Group Policy Editor→Administrative templates→All Settings→Enable Win32 long paths.
My yaml file:
pool:
name: 'My_Pool'
demands:
- agent.name -equals My_Agent
variables:
buildPlatform: 'x64'
buildConfiguration: 'Release'
solution: '$(System.DefaultWorkingDirectory)/XXX/YYY/MySolution.sln'
DotNet6Project: '$(System.DefaultWorkingDirectory)/XXX/YYY/DotNet6Project/MyProject.csproj'
CPPWrapper: '$(System.DefaultWorkingDirectory)/XXX/YYY/CPPWrapper/MyProject.vcxproj'
steps:
- task: NuGetToolInstaller#0
displayName: 'NuGet Tool Installer - NuGetToolInstaller#0'
name: 'NuGetToolInstaller'
inputs:
versionSpec: '>=6.1.0'
- task: NuGetCommand#2
displayName: 'NuGet Restore - NuGetCommand#2'
inputs:
command: 'restore'
restoreSolution: '$(solution)'
noCache: true
- task: BatchScript#1
displayName: 'Run BatchScript to create DLLs, Libs & Header - BatchScript#1'
inputs:
filename: '$(System.DefaultWorkingDirectory)/ICP/ZZZ/build_release.bat'
env:
PATH: 'C:\Program Files\CMake\bin'
- task: PowerShell#2
displayName: 'Run Powershell Script to unpack Packages from BatchScript for ZZZWrapper - PowerShell#2'
inputs:
filePath: '$(System.DefaultWorkingDirectory)/XXX/YYY/CPPWrapper/install_ZZZ_package.ps1'
# Workaround for MSBuild#1
- script: |
#echo off
setlocal enabledelayedexpansion
for /f "usebackq tokens=*" %%i in (`"!ProgramFiles(x86)!\Microsoft Visual Studio\Installer\vswhere.exe" -latest -products * -requires Microsoft.Component.MSBuild -find MSBuild\**\Bin\MSBuild.exe`) do (set msbuild_exe=%%i)
"!msbuild_exe!" "$(solution)" /p:Configuration="$(buildConfiguration)" /p:Platform="$(buildPlatform)" /p:PackageLocation="$(build.artifactStagingDirectory)" /t:rebuild
displayName: 'Build - Script'
# ---------- VSBuild ----------------
#- 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)'
# ---------- DotNetCoreCLI ----------
#- task: UseDotNet#2
# inputs:
# packageType: 'sdk'
# version: '6.x'
#- task: DotNetCoreCLI#2
# displayName: 'Build & Publish - DotNetCoreCLI#2'
# inputs:
# command: 'publish'
# publishWebProjects: false
# projects: '$(solution)'
# arguments: '--configuration $(buildConfiguration) --output $(Build.ArtifactStagingDirectory)'
# zipAfterPublish: false
# env:
# PATH: 'C:\Program Files\Microsoft Visual Studio\2022\Community\MSBuild\Microsoft\VC\v170'
- task: PublishBuildArtifacts#1
displayName: 'Publish Build Artifacts - PublishBuildArtifacts#1'
inputs:
PathtoPublish: '$(Build.ArtifactStagingDirectory)'
ArtifactName: 'XXXArtifact'
publishLocation: 'Container'
From your yaml file ,I understand you want to build a solution and then publish build artifact. Accroding the error of your described task, I would like to provide suggestions that you can check.
1 VSBuild#1
taskError information: No agent found in pool My_Pool which satisfies the specified demandsThis indicates there are no agents on your machine that meet the demand requirements. You should check whether exists the agent which name is My_Agend_Unity_1 and exists check for Cmd,msbuild,visualstudio,Agent.Version -gtVersion 2.153.1.
See more information refer to doc:pool definition
2  UseDotNet#2
There’s a warning warning NU1503: Skipping restore for project that indicates  the packages required for the project MyProject are not restored correctly. You should edit the affected project to add targets for restore.
Please refer to doc:NuGet Warning NU1503
About the error MSB4019,you should check whether the project path "C:\Microsoft.Cpp.Default.props" exists. Here’s a ticekt  similar to your issue.You can try to this workaround and see if it works.
3 MSBuild
MSBuildAbout error NETSDK1064, this error occurs when the build tools can't find a NuGet package that's needed to build a project. This is typically due to a package restore issue related to warning NU1503 inTask   UseDotNet#2`. You can refer this doc:NETSDK1064: Package not found to take some actions provided to resolve this error.

Azure DevOps: I'm caching nuget packages, but the Build task fails to use the cached packages

I'm using the Cache#2 DevOps task to cache nuget packages from multiple projects:
variables:
NUGET_PACKAGES: $(Pipeline.Workspace)/.nuget/packages
- task: Cache#2
displayName: 'NuGet cache'
inputs:
key: 'nuget | "$(Agent.OS)" | **/packages.lock.json,!**/bin/**,!**/obj/**'
restoreKeys: |
nuget | "$(Agent.OS)"
nuget
path: $(NUGET_PACKAGES)
cacheHitVar: 'CACHE_RESTORED'
- task: NuGetCommand#2
displayName: 'NuGet restore'
condition: ne(variables.CACHE_RESTORED, true)
inputs:
command: 'restore'
restoreSolution: '$(solution)'
- task: VSBuild#1
displayName: 'Build solution'
...
I'm following the documentation here:
https://learn.microsoft.com/en-us/azure/devops/pipelines/artifacts/caching-nuget?view=azure-devops
In the 'NuGet cache' step, if there is a cache, it is restored:
Resolved to: nuget|"Windows_NT"|Gor2Y1OZWvAeaan3RC3GH9D0ldp6z17wm6JB2YUxrS0=
There is a cache hit: `nuget|"Windows_NT"|Gor2Y1OZWvAeaan3RC3GH9D0ldp6z17wm6JB2YUxrS0=`
Path =
Type = tar
Code Page = UTF-8
Characteristics = ASCII
Everything is Ok
Folders: 6022
Files: 8938
Size: 1894324465
Compressed: 7660544
Process exit code: 0
Cache restored.
If there is a cache hit, the 'NuGet restore' task is skipped:
Evaluating: ne(variables['CACHE_RESTORED'], True)
Expanded: ne('true', True)
Result: False
Then comes my problem. The 'Build solution' task fails with thousands of errors like these
##[error]NHO.Core\IdentityServerClientStartup.cs(32,12): Error CS0246: The type or namespace name 'OwinStartupAttribute' could not be found (are you missing a using directive or an assembly reference?)
It cannot resolve references to classes in NuGet packages.
Any idea why this fails? I'm following the documentation exactly, but I don't know if I'm still missing something?
Update: Possible solution/source of error
It seems to be an error in the documentation.
If I run the NuGet restore step normally, without the condition
- task: NuGetCommand#2
displayName: 'NuGet restore'
inputs:
command: 'restore'
restoreSolution: '$(solution)'
it is a lot quicker than normal (20 seconds instead of 2 minutes), so I'm guessing it uses the cache.
The documentation provides only a basic case that all packages and references are stored in .nuget/packages and no assets files are required. In this case, the users can skip the restore task and just perform the cache task.
However, in many other cases, performing a restore task is necessary if using Microsoft-hosted agent. Since most packages are already cached by cache task, the running time of nuget restore task will be significantly reduced.

SonarQube: No analysis found in this build after applying include pattern

I am trying to integrate SonarQube in a CI-pipeline in Azure DevOps. I used the exact configuration that I used in other pipelines where everything runs smoothly. However, this pipeline can't find the analysis in the SonarQube Publish step as shown in the logs below.
##[debug] /home/vsts/work/_temp/sonar (directory)
##[debug] /home/vsts/work/_temp/sonar/Company.Service-CI[sonarqube-test][121226][2022-01-19] (directory)
##[debug] /home/vsts/work/_temp/sonar/Company.Service-CI[sonarqube-test][121226][2022-01-19]/9731b11b-6af8-d211-752d-e8fe0770156c (directory)
##[debug] /home/vsts/work/_temp/sonar/Company.Service-CI[sonarqube-test][121226][2022-01-19]/9731b11b-6af8-d211-752d-e8fe0770156c/report-task.txt (file)
##[debug]4 results
##[debug]found 4 paths
##[debug]applying include pattern
##[debug]adjustedPattern: '/home/vsts/work/_temp/sonar/Company.Service-CI[sonarqube-test][121226][2022-01-19]/**/report-task.txt'
##[debug]0 matches
##[debug]0 final results
##[debug][SQ] Searching for sonar/Company.Service-CI[sonarqube-test][121226][2022-01-19]/**/report-task.txt - found 0 file(s)
##[warning]No analyses found in this build! Please check your build configuration.
I find this problem hard to solve because it seems like the analysis report is there but after applying the include pattern there are zero matches. The pipeline contains the following steps:
stages:
- stage:
jobs:
- job: Build_Restore_and_Run_Unit_Tests
pool:
vmImage: ubuntu-latest
steps:
- task: SonarQubePrepare#5
displayName: SonarQube
inputs:
SonarQube: SonarQube
scannerMode: MSBuild
projectKey: $(sonarQubeProjectKey)
projectName: $(sonarQubeProjectName)
extraProperties: |
sonar.cs.opencover.reportsPaths=$(Agent.TempDirectory)/*/coverage.opencover.xml
- task: DotNetCoreCLI#2
displayName: Restore
inputs:
command: 'restore'
projects: 'src/**/*.csproj'
feedsToUse: 'select'
vstsFeed: '989127ec-b6ef-4c8c-ae54-90dec743281d'
- task: DotNetCoreCLI#2
displayName: Build
inputs:
command: build
projects: |
**/*.Test.csproj
arguments: '--configuration $(buildConfiguration) --no-restore'
- task: DotNetCoreCLI#2
displayName: Test
inputs:
command: test
projects: '**/*.Test.csproj'
nobuild: true
arguments: '--no-restore --collect:"XPlat Code Coverage" -- DataCollectionRunSettings.DataCollectors.DataCollector.Configuration.Format=cobertura,opencover'
publishTestResults: true
- task: PublishCodeCoverageResults#1
displayName: Publish code coverage
inputs:
codeCoverageTool: Cobertura
summaryFileLocation: $(Agent.TempDirectory)/*/coverage.cobertura.xml
- task: SonarQubeAnalyze#5
displayName: Run code analysis
- task: SonarQubePublish#5
displayName: Publish quality gate result
inputs:
pollingTimeoutSec: '300'
My attempts to fix this issue:
Currently I am using ubuntu-latest. I have tried a Windows image.
Applied time-outs.
Upgraded the SonarQube steps from major version 4 to 5.
Added an unique GUID to each projects csproj.
As Mickaël Caro stated on my similar post in the SonarSource community forum:
Unfortunately some characters are not recognized nor parsed correctly when we try to find the report path (We do have this issue filed here : [VSTS-240] Escape regex characters when finding report path file. - SonarSource).
I changed the [ ] in the name of the build to ( ), and the analysis runs smoothly.

AzureStaticWebApp#0 push from artifacts

I've a CD pipeline that builds a project (multiple times for different environments) and publishes / saves the ./dist directories as one stage. I can download each environment and run locally as expected.
Each environment build is a stage that needs a manual approval. This is where I am getting lost. Each stage shows the correct artifact being pulled into the stage BUT the AzureStaticWebApp#0 -> app_location input results in a "Could not detect this directory." error.
To recap:
After building the project and saving as an artifact (I can manually download and verify) I am unable to push that built code to Azure Static Web App as it cannot be found. I've tried any number of combinations to no effect. Any advice?
I'm using templates, here is the Push Built Project to Azure Static Web Apps template
When this template runs, I can see jobs running and successfully pulling down the right artifact with this output:
Successfully downloaded artifacts to /home/vsts/work/1/
Finishing: Download Artifact
But the AzureStaticWebApp#0 task gives this error:
App Directory Location: '/home/vsts/work/1/DEV' is invalid. Could not detect this directory. Please verify your deployment configuration file reflects your repository structure.
parameters:
- name: environment
default: development
type: string
- name: variableGroup
default: development-variables-group
type: string
jobs:
- deployment:
displayName: 'Deploy to'
environment: ${{parameters.environment}}
variables:
- group: ${{parameters.variableGroup}}
pool:
vmImage: ubuntu-latest
strategy:
runOnce:
deploy:
steps:
- task: AzureStaticWebApp#0
inputs:
app_location: '$(Pipeline.Workspace)/DEV'
api_location: 'api'
output_location: 'dist'
skip_app_build: true
env:
azure_static_web_apps_api_token: $(deployment-token)
EDIT
Does the task AzureStaticWebApp not have access to anything outside the project?
- deployment:
displayName: 'Deploy to'
environment: ${{parameters.environment}}
variables:
- group: ${{parameters.variableGroup}}
pool:
vmImage: ubuntu-latest
strategy:
runOnce:
deploy:
steps:
- checkout: self
submodules: true
# This step pulls down a complied site. E.g DEV/index.htm, ./images, staticwebapp.config.json
# That has an output like:
# Downloading DEV/index.html to /home/vsts/work/1/DEV/index.html
# Successfully downloaded artifacts to /home/vsts/work/1/
- download: current
artifact: DEV
- task: AzureStaticWebApp#0
inputs:
# I've tried many different values for app_location but all return back not found error
app_location: '/DEV'
api_location: 'api'
output_location: 'dist'
skip_app_build: true
env:
azure_static_web_apps_api_token: $(deploymenttoken)
Solved --- well found a way to make it work.
The build step created 'app/dist' directory and content
The 'app/dist' folder only is published as an
artifact
When downloading the artifact you need to 'put it back'
into the project. In this case DEV/ -> app/dist.
- task: DownloadPipelineArtifact#2
inputs:
artifact: DEV
path: ./app/dist # Put build artifact back into the project
displayName: "Download artifacts"
- task: AzureStaticWebApp#0
inputs:
app_location: 'app/dist'
api_location: 'api'
output_location: 'dist'
skip_app_build: true
env:
azure_static_web_apps_api_token: $(deploymenttoken)
app_location specifies the root of your application code. The property should point to a location in your repo.
Check the documentation here: https://learn.microsoft.com/en-us/azure/static-web-apps/publish-devops
Also, https://github.com/Azure/static-web-apps/issues/5#issuecomment-855309544
There are two other solutions described in #552 that do not require adding the DownloadPipelineArtifact#2 step.
The solution that worked for me was to set the workingDirectory to the pipeline's artifact location. Then set the app_location value relative to the workingDirectory
For example, if your artifact was downloaded to $(Pipeline.Workspace)/MyBuild/drop
Your properties would be:
app_location: /drop
workingDirectory: $(Pipeline.Workspace)/MyBuild
yml snippet:
- task: AzureStaticWebApp#0
displayName: Publish Static Web App
inputs:
app_location: /drop # The name of your artifact
output_location: "" # Leave this empty
skip_app_build: true
azure_static_web_apps_api_token: $(deployment-token)
# The path where your artifact was downloaded
workingDirectory: $(Pipeline.Workspace)/MyBuild
This is really confusing because every other pipeline task accepts absolute paths but AzureStaticWebApp#0 requires a relative path for app_location.

Packages failed to publish due to TypeError: Cannot read property 'toLowerCase' of null

In my azure devops pipeline. A conda package is build firstly and published via UniversalPackages#0 task.
The build and upload code snippet is shown below
- stage: build_upload_package
displayName: Build and upload package
pool:
name: Private Agent Eve
jobs:
- job: build_upload_package
displayName: Build and Upload Package
condition: and(succeeded(), eq(variables['build.sourceBranch'], 'refs/heads/release'))
container:
image: <azureacr_repo.io>/conda:latest //modified to remove the information
endpoint: NameOfTheServiceConnection //modified to remove the information
steps:
- bash: |
echo "##vso[task.prependpath]$CONDA/bin"
conda build . --output-folder $(Build.ArtifactStagingDirectory)
displayName: Build Package
- bash: echo "##vso[task.setvariable variable=packageName]$(basename $(gitRepoName))"
displayName: Set Package Name
- task: UniversalPackages#0 //Error appears here
displayName: Upload to Azure Universal Packages
inputs:
command: publish
publishDirectory: '$(Build.ArtifactStagingDirectory)'
vstsFeedPublish: 'project_1/feed_1' //modified to remove the information
vstsFeedPackagePublish: '$(packageName)'
versionOption: patch
packagePublishDescription: 'upload a Conda Package'
The error for Universal UniversalPackages task is show below
2020-11-24T17:54:48.9628862Z ##[section]Starting: Upload to Azure Universal Packages
2020-11-24T17:54:48.9645737Z ==============================================================================
2020-11-24T17:54:48.9646470Z Task : Universal packages
2020-11-24T17:54:48.9647068Z Description : Download or publish Universal Packages
2020-11-24T17:54:48.9647636Z Version : 0.175.0
2020-11-24T17:54:48.9648154Z Author : Microsoft Corporation
2020-11-24T17:54:48.9648809Z Help : https://learn.microsoft.com/azure/devops/pipelines/tasks
2020-11-24T17:54:48.9649526Z ==============================================================================
2020-11-24T17:54:49.4896147Z SYSTEMVSSCONNECTION exists true
2020-11-24T17:54:50.1267511Z Downloading: https://08wvsblobprodsu6weus73.vsblob.vsassets.io/artifacttool/artifacttool-linux-x64-Release_0.2.172.zip?sv=2019-02-02&sr=b&sig=FvnCFjIg7ZBmIapFcCcWDC1%2F7pajvzvgo0fR2Y3YYeU%3D&spr=https&se=2020-11-24T18%3A54%3A51Z&sp=r&P1=1606243791&P2=11&P3=2&P4=1nPT99OOlNXc9xNzoCS6LpVATo%2bW4fIskTJ8u6olWMk%3d
2020-11-24T17:54:56.4979070Z Caching tool: ArtifactTool 0.2.172 x64
2020-11-24T17:54:56.7183832Z SYSTEMVSSCONNECTION exists true
2020-11-24T17:54:58.7313555Z ##[error]TypeError: Cannot read property 'toLowerCase' of null
2020-11-24T17:54:58.7323845Z ##[error]Packages failed to publish
2020-11-24T17:54:58.7641267Z ##[section]Finishing: Upload to Azure Universal Packages
Question:
How can I solve this issue?
I think I found the error, gitRepoName is a template parameter, it should be accessed as ${{ gitRepoName }} not the $(gitRepoName)
I did some tests on this task:UniversalPackages#0. I noticed the following reminder in the task:
Universal package names must be one or more lowercase alphanumeric segments separated by a dash, dot or underscore. The package name must be under 256 characters.
When your packageName contains capital letters or other special characters, this task will fail.
You could try the following scripts:
- task: PowerShell#2
inputs:
targetType: 'inline'
script: |
$name = $(basename $(gitRepoName)).ToLower()
Write-Host "##vso[task.setvariable variable=packageName]$name"
- task: UniversalPackages#0
inputs:
command: 'publish'
publishDirectory: '$(Build.ArtifactStagingDirectory)'
vstsFeedPublish: 'project_1/feed_1'
vstsFeedPackagePublish: '$(packageName)'
versionOption: 'patch'
The Powershell task could Lowercase the RepoName.