1717# https://eng.ms/docs/products/onebranch/build/releasepipelines/releaseworkflows/deploymentjob
1818
1919parameters :
20- # Human-readable package name ( used in display strings) .
21- - name : packageDisplayName
20+ # The NuGet package name, used to form the default packagePath and for display strings.
21+ - name : packageName
2222 type : string
2323
2424 # The pipeline artifact name to download (OneBranch naming: drop_<stage>_<job>).
@@ -34,21 +34,43 @@ parameters:
3434 type : boolean
3535 default : false
3636
37- # Globbing pattern to match .nupkg and .snupkg files within the downloaded artifact.
38- - name : packagePattern
37+ # The path to the NuGet package to publish, relative to the root of the downloaded pipeline
38+ # artifact. For example, if we're publishing the SqlClient package, and the build job publishes a
39+ # pipeline artifact with the following structure:
40+ #
41+ # drop_BuildAndTest_PackageReference/
42+ # ├── Microsoft.Data.SqlClient.5.0.0.nupkg
43+ # ├── Microsoft.Data.SqlClient.5.0.0.snupkg
44+ # ├── Microsoft.Data.SqlClient.Extensions.Abstractions.1.0.0.nupkg
45+ # └── other-file.txt
46+ #
47+ # Then the packagePath should be 'Microsoft.Data.SqlClient.5.0.0.nupkg'.
48+ #
49+ # Defaults to '${{ parameters.packageName }}.*.nupkg' to match any version of the package.
50+ #
51+ - name : packagePath
3952 type : string
40- default : ' **/*.nupkg;**/*.snupkg '
53+ default : ' '
4154
42- # When true, list packages that would be published without actually pushing. Use for non-official
43- # pipelines to validate the release stage without risk.
44- - name : dryRun
55+ # When true, lists the package that would be published without actually pushing.
56+ - name : isDryRun
4557 type : boolean
4658 default : false
4759
4860# Read more: https://eng.ms/docs/products/onebranch/release/yamlreleasepipelines/pipelinebasics#what-is-a-onebranch-release-yaml-pipeline
4961jobs :
50- - job : publish_${{ replace(parameters.packageDisplayName, '.', '_') }}
51- displayName : Publish ${{ parameters.packageDisplayName }}
62+ - job : publish_${{ replace(parameters.packageName, '.', '_') }}
63+ displayName : Publish ${{ parameters.packageName }}
64+
65+ variables :
66+ - name : ob_outputDirectory
67+ value : $(Build.SourcesDirectory)/packages
68+
69+ - name : artifactPath
70+ value : $(Pipeline.Workspace)/${{ parameters.artifactName }}
71+
72+ - name : packageToPush
73+ value : $(artifactPath)/${{ coalesce(parameters.packagePath, format('{0}.*.nupkg', parameters.packageName)) }}
5274
5375 # Template context inputs are used to pass parameters to the deployment job since it doesn't
5476 # automatically download pipeline artifacts.
5880 inputs :
5981 - input : pipelineArtifact
6082 artifactName : ${{ parameters.artifactName }}
61- targetPath : $(Pipeline.Workspace)/${{ parameters.artifactName }}
62-
63- variables :
64- - name : ob_outputDirectory
65- value : $(Build.SourcesDirectory)/packages
83+ targetPath : $(artifactPath)
6684
6785 pool :
6886 type : release
@@ -71,21 +89,20 @@ jobs:
7189
7290 # Artifacts are downloaded via templateContext.inputs per OneBranch requirements.
7391
74- - ${{ if eq(parameters.dryRun , true) }} :
92+ - ${{ if eq(parameters.isDryRun , true) }} :
7593 - pwsh : |
76- Write-Host "##[section]DRY RUN — the following packages may be published:"
77- $nupkgs = Get-ChildItem -Path "$(Pipeline.Workspace)/${{ parameters.artifactName }}" -Filter "*.nupkg" -Recurse -ErrorAction SilentlyContinue
78- $snupkgs = Get-ChildItem -Path "$(Pipeline.Workspace)/${{ parameters.artifactName }}" -Filter "*.snupkg" -Recurse -ErrorAction SilentlyContinue
79- if ($nupkgs) { $nupkgs | ForEach-Object { Write-Host $_.FullName } } else { Write-Host "(no .nupkg found)" }
80- if ($snupkgs) { $snupkgs | ForEach-Object { Write-Host $_.FullName } } else { Write-Host "(no .snupkg found)" }
81- Write-Host "##[warning]Dry run mode — no packages were pushed."
82- displayName: Dry Run — List ${{ parameters.packageDisplayName }} packages
94+ Write-Host "##[section]DRY RUN — The following packages would be published:"
95+
96+ Get-ChildItem -Path "$(packageToPush)" -ErrorAction SilentlyContinue
97+
98+ Write-Host "##[warning]DRY RUN — No packages were pushed."
99+ displayName: Dry Run — List ${{ parameters.packageName }} packages
83100
84101 - ${{ else }} :
85102 - task : NuGetCommand@2
86- displayName : Push ${{ parameters.packageDisplayName }} to NuGet
103+ displayName : Push ${{ parameters.packageName }} to NuGet
87104 inputs :
88105 command : push
89- packagesToPush : $(Pipeline.Workspace)/${{ parameters.artifactName }}/${{ parameters.packagePattern }}
106+ packagesToPush : $(packageToPush)
90107 nuGetFeedType : external
91108 publishFeedCredentials : ${{ parameters.nugetServiceConnection }}
0 commit comments