Reputation: 1
I create a task to download the latest artifact from another pipeline and in sequence identify the file to make a silent install by command line.
- task: DownloadPipelineArtifact@2
inputs:
source: 'specific'
project: 'TestApp'
pipeline: 'TestApp'
runVersion: 'latest'
branchName: 'refs/heads/master'
allowPartiallySucceededBuilds: true
patterns: '**/*.msi'
downloadPath: $(Build.ArtifactStagingDirectory)
- task: CmdLine@2
inputs:
script: |
cd $(Build.ArtifactStagingDirectory)/TestApp-20201015.2
TestApp.1-setup.msi /s /v
Is there a variable where the name of the last artifact generated from a pipeline is stored? Like this:
- task: CmdLine@2
inputs:
script: |
cd $(Build.ArtifactStagingDirectory)/$(latestArtifact)
$(latestInstaller).msi /s /v
I tried to use $(Build.DefinitionName) or TestApp-$(Build.BuildNumber), but it didn't work. I apologize right now because I'm a beginner on Azure and I'm having trouble understanding how pipelines work.
Upvotes: 0
Views: 400
Reputation: 35494
I am afraid that there is no out-of-the-box variable that can represent the latest downloaded artifacts.
But you could create a variable in pipeline to get the Artifacts name.
Based on my test, when you use the Download Pipeline Artifacts task
, the pipeline will generate an environment variable: $(DOWNLOADPIPELINEARTIFACT.BUILDNUMBER)
.
Then you could use Powershell to run Rest API to get the artifacts name.
Here is my sample:
steps:
- powershell: |
$token = "PAT"
$url=" https://dev.azure.com/{Organization Name}/{Project Name}/_apis/build/builds/$(DOWNLOADPIPELINEARTIFACT.BUILDNUMBER)/artifacts?api-version=6.0"
$token = [System.Convert]::ToBase64String([System.Text.Encoding]::ASCII.GetBytes(":$($token)"))
$response = Invoke-RestMethod -Uri $url -Headers @{Authorization = "Basic $token"} -Method Get -ContentType application/json
$latestvalue = $response.value.name
echo $latestvalue
echo "##vso[task.setvariable variable=latest]$latestvalue"
displayName: 'PowerShell Script'
Then you could create a variable name:$(latest)
. Its value is the name of the latest artifact(e.g. TestApp-20201015.2
).
You could use the variable in the next task.
cd $(Build.ArtifactStagingDirectory)/$(latest)
TestApp.1-setup.msi /s /v
For the latest installer name
You can hard code this value. From the name of the .msi file, it does not seem to be related to the variable of the pipeline, so I am not sure whether a variable can be created to represent it.
Upvotes: 2