I am looking for a task which could download a latest commit based on the tag from Azure Repos. I mean whole files/folders structures from Azure Repos which is than use to build the application. Then use it for different environments’, like Test, than Integration, and Production. Now, I am a bit confused with the order/tasks/reusability:
- The first stage which is called Build could download that package from Azure Repo and than publish? So two tasks
DownloadGitHubRelease@0
andPublishPipelineArtifact@1
to publish that artifact? By the way I do not see the task which could download packages from Azure Repo, only that oneDownloadGitHubRelease@0
which is designed for GitHub, am I right? - The second stage called Test should download that artifact with
DownloadBuildArtifacts@1
(means above package), and extract it withExtractFiles@1
. - The same steps/tasks such as above for Production stage.
Is that correct way? Or is that any better approach? My beginning:
trigger:
branches:
include:
- master/*
resources:
repositories:
- repository: pipeline
type: git
name: pipeline
ref: auto/*
- repository: Automotive
type: git
name: autoomotive
ref: master
variables:
- template: variables.yml
- name: releaseTag
value: '18.11.0'
stages:
- stage: Build
jobs:
- job: DownloadPackage
pool:
vmImage: 'ubuntu-latest'
steps:
- task: DownloadGitHubRelease@0
inputs:
repository: 'OEM/Automotive'
tags: |
[latest]
artifactName: 'AutomotivePackage'
downloadPath: '$(System.ArtifactsDirectory)'
- task: PublishPipelineArtifact@1
inputs:
targetPath: '$(System.ArtifactsDirectory)/AutomotivePackage'
artifactName: 'AutomotivePackage'
publishLocation: 'pipeline'
- stage: Test
jobs:
- job: TestDeployment
pool:
vmImage: 'ubuntu-latest'
steps:
- task: DownloadPipelineArtifact@2
inputs:
buildType: 'current'
artifactName: 'AutomotivePackage'
downloadPath: '$(System.ArtifactsDirectory)'
- task: ExtractFiles@1
inputs:
archiveFilePatterns: '$(System.ArtifactsDirectory)/AutomotivePackage/*.tar.gz'
destinationFolder: '$(System.DefaultWorkingDirectory)/Automotive'
- stage: Production
jobs:
- job: ProdDeployment
pool:
vmImage: 'ubuntu-latest'
steps:
- task: DownloadPipelineArtifact@2
inputs:
buildType: 'current'
artifactName: 'AutomotivePackage'
downloadPath: '$(System.ArtifactsDirectory)'
- task: ExtractFiles@1
inputs:
archiveFilePatterns: '$(System.ArtifactsDirectory)/AutomotivePackage/*.tar.gz'
destinationFolder: '$(System.DefaultWorkingDirectory)/Automotive'
My imagination is that developer commit new package with tag, than Azure Devops takes the changes and run pipeline.
2
Answers
It sounds like all you need is to add a deployment step to your existing build pipeline. This will copy the most recent build artifacts to your desired location. Since your location is in your Azure environment you’ll want to look at all the deployment tasks and decide which one does exactly what you want.
for example:
Is simple and straight forward. There are other deployment tasks if your need is more in depth than simple copy.
From your example pipeline, it looks like you could add a job with this task to each of your stages, and this will perform the deployment of the artifacts.
I recommend the destination folder is NOT the working directory for your websites until you are sufficiently happy with the way your deployment tasks are working.
You may also need some powershell, or other script, tasks to stop your services or websites and restart them after deployment is complete.
Based on comment and question description, the pipeline need to listen the commit tag changes in Automotive repo, then trigger pipeline and download azure repo based on related changed tag.
To meet your requirement, you can set tag trigger in repo resources and directly use
- checkout: repoalias
to download the azure repo based on related changed tag.Tag trigger:
Download Azure Repo:
Here is an example:
When developers commit new package with tag to azure repo, it will automatically trigger the pipeline and the checkout step will download the azure repo with the related committed tag.
If you need to download the repo which is used to create pipeline, you can add – checkout: self to check the related repo.
Here is the doc about checkout definition.
Result: