I am trying to build and publish multiple azure function projects within a single solution using YAML pipelines but when I publish the packages they are overwriting each other so I only publish the last project built.
I use these steps to build:
- task: DotNetCoreCLI@2
displayName: 'Restore project dependencies'
inputs:
command: 'restore'
feedsToUse: 'config'
nugetConfigPath: Nuget.config
projects: '**/*.csproj'
- task: DotNetCoreCLI@2
displayName: 'Build the project - $(configuration)'
inputs:
command: 'build'
arguments: '--no-restore --configuration $(configuration) -p:DesktopBuildPackageLocation="$(Build.ArtifactStagingDirectory)\Functions" -p:ArtifactStagingDirectory="$(Build.ArtifactStagingDirectory)\Artifacts"'
projects: '**/*.csproj'
- task: DotNetCoreCLI@2
displayName: 'Publish the project - $(configuration)'
inputs:
command: 'publish'
projects: '**/*Functions.csproj'
publishWebProjects: false
arguments: '--no-build --configuration $(configuration) --output $(Build.ArtifactStagingDirectory)\Functions'
zipAfterPublish: true
modifyOutputPath: true
- publish: '$(Build.ArtifactStagingDirectory)\Functions'
displayName: 'Publish drop'
artifact: functions
Is there a way I can publish the functions by project? I tried the VSBuild task to build the solution but when trying to deploy to Azure using the AzureFunctionApp task, it errors out saying msBuild packages are not supported.
Any suggestions welcome!
Is there a way I can publish the functions by project?
Based on your description, you have multiple projects in a single solution file.
As far as I know, in Do.net Publish task, you could set the publishWebProjects: false
. Then the functions will be published by project.
You could refer to my sample:
- task: DotNetCoreCLI@2
displayName: Restore
inputs:
command: restore
projects: '**/*.csproj'
- task: DotNetCoreCLI@2
displayName: Build
inputs:
projects: '**/*.csproj'
arguments: '--no-restore --configuration $(configuration) -p:DesktopBuildPackageLocation="$(Build.ArtifactStagingDirectory)\Functions" -p:ArtifactStagingDirectory="$(Build.ArtifactStagingDirectory)\Artifacts"'
- task: DotNetCoreCLI@2
displayName: Publish
inputs:
command: publish
publishWebProjects: false
projects: '**/*.csproj'
arguments: '--no-build --configuration $(configuration) --output $(Build.ArtifactStagingDirectory)/Functions'
zipAfterPublish: True
continueOnError: true
- task: PublishBuildArtifacts@1
displayName: 'Publish Artifact'
inputs:
PathtoPublish: ' $(build.artifactstagingdirectory)'
condition: succeededOrFailed()
Result:
I figured out a pattern that worked for me. Instead of trying to publish all the projects within my solution with just one task, I split them up and gave each one it's own task. So I went from this:
- task: DotNetCoreCLI@2
displayName: 'Publish Functions'
inputs:
command: publish
projects: '**/*.Functions.csproj'
publishWebProjects: false
arguments: '--no-build --configuration ${{ variables.configuration }} -o $(Build.ArtifactStagingDirectory)\Functions'
modifyOutputPath: true
zipAfterPublish: true
to this:
- task: DotNetCoreCLI@2
displayName: 'Publish Project 1 Functions'
inputs:
command: publish
projects: '**/Project1.Functions.csproj'
publishWebProjects: false
arguments: '--no-build --configuration ${{ variables.configuration }} -o $(Build.ArtifactStagingDirectory)\Functions\Project1'
modifyOutputPath: true
zipAfterPublish: true
- task: DotNetCoreCLI@2
displayName: 'Publish Project2 Functions'
inputs:
command: publish
projects: '**/Project2.Functions.csproj'
publishWebProjects: false
arguments: '--no-build --configuration ${{ variables.configuration }} -o $(Build.ArtifactStagingDirectory)\Functions\Project2'
modifyOutputPath: true
zipAfterPublish: true
I kept the rest of my template the same as in my original post.
Thanks for all the help.
Instead of Publish Pipeline Artifacts task you could use artifact.upload logging command to upload multiple artifacts from a single script step:
Upload: Upload an artifact
##vso[artifact.upload]local file path
Usage
Upload a local file into a file container folder, and optionally publish an artifact as
artifactname
.Properties
containerfolder
= folder that the file will upload to, folder will be created if needed.
artifactname
= artifact name. (Required)
- pwsh: |
Get-ChildItem -LiteralPath '$(Build.ArtifactStagingDirectory)\Functions' -Filter '*.zip' -File |
ForEach-Object {
'##vso[artifact.upload containerfolder={0};artifactname={0}]{1}' -f $_.BaseName, $_.FullName
}
displayName: Publish artifacts
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.