Reputation: 1286
Setting up a yml based azure build pipeline for which publishing artifacts require timestamp based name. Trying to do something like this
'ArtifactName' + currentTimeStamp
How can this be done in an yml file?
Upvotes: 3
Views: 3704
Reputation: 2180
You can set the build name in the first line of yml script.
name: $(Date:yyyyMMdd)-$(Hours)$(Minutes)$(Seconds)
See tokens here: https://learn.microsoft.com/en-us/azure/devops/pipelines/process/run-number?view=azure-devops&tabs=yaml
And then set the artifactName concatenating the $(Build.BuildNumber) that represents the name set before
artifactName: 'ArtifactName-$(Build.BuildNumber)'
Upvotes: 0
Reputation: 40583
This should give you expected result:
trigger:
- master
pool:
vmImage: ubuntu-latest
steps:
- pwsh: |
Write-Host "Setting up the date time for build variable"
$date=$(Get-Date -format yyyyMMdd-Hmmss)
Write-Host "##vso[task.setvariable variable=currentTimeStamp]$date"
displayName: 'Geting timestamp'
- task: PublishPipelineArtifact@1
inputs:
targetPath: '$(Pipeline.Workspace)'
artifact: 'ArtifactName-$(currentTimeStamp)'
publishLocation: 'pipeline'
Upvotes: 6