Still trying to get a full grasp on the Azure Pipelines and what I can do with those...
I've managed to finally get my little .NET Core command line utility built with Azure Pipelines - now trying to publish it as a build artifact.
With this YAML, I can build and package the tool:
- task: DotNetCoreCLI@2
displayName: 'dotnet build'
inputs:
command: 'build'
projects: '$(solution)'
- task: DotNetCoreCLI@2
displayName: 'dotnet publish'
inputs:
command: publish
publishWebProjects: False
arguments: '--configuration $(BuildConfiguration) --output $(Build.ArtifactStagingDirectory)'
zipAfterPublish: True
- task: PublishBuildArtifacts@1
inputs:
pathtoPublish: '$(Build.ArtifactStagingDirectory)'
artifactName: 'MyTool_LatestBuild'
But in the published build artifacts, I only get a file a.zip
- is there any way I can influence the name of that ZIP archive?? I'd really love to have something like MyTool_2020_Sep_08.zip
or MyTool_v1.5.7.zip
something.... but how can I do that?? Can't seem to find anything very useful anywhere on the interwebs ... any inputs?
Thanks!
If you mean you want to get the Artifact Name which is defined in Publish Build Artifacts task in Build process (By default it's Drop ), then you can run below PowerShell script calling the REST API to retrieve the value and set a variable with logging command. After that you can use the variable in subsequent tasks...
Understand the azure-pipelines. Usually, this file is named azure-pipelines. yml and is located at the root of your repo. Navigate to the Pipelines page in Azure Pipelines, select the pipeline you created, and choose Edit in the context menu of the pipeline to open the YAML editor for the pipeline.
$(Build. SourcesDirectory) : The local path on the agent where your source code files are downloaded. For example: c:\agent_work\1\s By default, new build definitions update only the changed files. You can modify how files are downloaded on the Repository tab.
If you publish the artifacts into Azure Pipelines in a pipeline run, you can see the published artifacts on the details page of this run. The artifact files are stored in a folder that named with the artifact name you specified when publishing the artifact.
1.Agree with Vernou. You can customize the name by specifying the folder name that contains your binaries. So we need to modify the --output
argument of dotnet publish
step and PathtoPublish
argument of PublishBuildArtifacts
step.
2.But to get Date time, you can use Build.BuildNumber which is predefined variables.
My working sample:
name: $(Date:yyyyMMdd)$(Rev:.r)
steps:
- task: DotNetCoreCLI@2
inputs:
command: 'build'
projects: '**/*.csproj'
- task: DotNetCoreCLI@2
displayName: 'dotnet publish'
inputs:
command: publish
publishWebProjects: False
arguments: '--configuration $(BuildConfiguration) --output $(Build.ArtifactStagingDirectory)/MyTool_$(Build.BuildNumber)'
zipAfterPublish: True
- task: PublishBuildArtifacts@1
inputs:
PathtoPublish: '$(Build.ArtifactStagingDirectory)/MyTool_$(Build.BuildNumber)'
ArtifactName: 'MyTool_LatestBuild'
publishLocation: 'Container'
More details about using BuildNumber to get date, you can check Configure run or build numbers.
The result:
We can control the format via modifying how we define the Build.BuildNumber
(In Yaml, it's name
). If we define name: $(Date:yyyyMMdd)
, then the output zip would be MyTool_20200908.zip
.
EDIT: Loking at vernou's answer - i was wrong, i'll leave this here because some may prefer to have different steps and we all love copying from SO.
The Task you're using does not contain that power, but you can (like i have) opt to zip it yourself instead:
- task: DotNetCoreCLI@2
inputs:
command: 'publish'
publishWebProjects: false
projects: |
**/*Client.csproj
**/*WorkerService.csproj
**/*Server.csproj
arguments: '-c $(BuildConfiguration) -o $(Build.StagingDirectory)/ci-build --no-build --self-contained -r $(runtime)'
zipAfterPublish: false
# Archive the /staging/ci-build folder to /staging/RemoteData.<BuildNumber>
- task: ArchiveFiles@2
inputs:
rootFolderOrFile: '$(Build.StagingDirectory)/ci-build'
includeRootFolder: false
archiveType: 'zip'
archiveFile: '$(Build.ArtifactStagingDirectory)/RemoteData.$(Build.BuildNumber).zip'
replaceExistingArchive: true
# Publish the zipfile as artifact
- task: PublishBuildArtifacts@1
inputs:
PathtoPublish: '$(Build.ArtifactStagingDirectory)/RemoteData.$(Build.BuildNumber).zip'
ArtifactName: 'RemoteData.$(Build.BuildNumber)'
publishLocation: 'Container'
This has the added benefit of being able to more closely manage your jobs:
As you can see each step is laid out separately here.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With