Now that we've pushed our assets to our git repo and created our Azure infrastructure, we are now going to finish the Continuous Integration part of our DevOps pipeline. Our goal is going to be simple, zip up our assets and get them ready for deployment.
Open up your YAML file and add the following section to zip up our assets.
- task: ArchiveFiles@2
displayName: 'Zip hero images'
inputs:
rootFolderOrFile: 'heroImages'
includeRootFolder: false
archiveType: 'zip'
archiveFile: '$(Build.ArtifactStagingDirectory)/$(Build.BuildId).zip'
replaceExistingArchive: true
The above will simply create a zip file with the contents of our heroImages folder, if we where to check off includeRootFolder, our zip would contain the heroImages folder, but with it set to false it will simply be a build number.zip file with the contents of heroImages.
Next we have to move our Zip file to a staging area, we can do this with the following
- task: PublishBuildArtifacts@1
displayName: 'Publish zipped assets for deployment'
inputs:
PathtoPublish: '$(Build.ArtifactStagingDirectory)/$(Build.BuildId).zip'
ArtifactName: 'drop'
publishLocation: 'Container'
The above takes our zipped file and makes it available in a folder called drop for our Continuous Deployment step, otherwise known as CD.
For good measure, here's our YAML file start to finish.
# Starter pipeline
# Start with a minimal pipeline that you can customize to build and deploy your code.
# Add steps that build, run tests, deploy, and more:
# https://aka.ms/yaml
trigger:
- dev
- test
- master
variables:
${{ if startsWith(variables['Build.SourceBranch'], 'refs/heads/') }}:
branchName: $[ replace(variables['Build.SourceBranch'], 'refs/heads/', '') ]
${{ if startsWith(variables['Build.SourceBranch'], 'refs/pull/') }}:
branchName: $[ replace(variables['System.PullRequest.TargetBranch'], 'refs/heads/', '') ]
name: 'pav'
location: 'westeurope'
azureSubscription: 'Pavs Subscription(0000000000-0000-0000-0000-000000000000)'
pool:
vmImage: 'windows-latest'
steps:
- script: |
echo BranchName = '$(branchName)'
echo name = '$(name)'
echo location = '$(location)'
echo azureSubscription = '$(azureSubscription)'
displayName: 'List YAML variables'
- task: AzurePowerShell@5
displayName: Build azure cdn infrastructure
inputs:
azureSubscription: '$(azureSubscription)'
ScriptType: 'FilePath'
ScriptPath: '$(Build.SourcesDirectory)/AzureInfrastructure.ps1'
ScriptArguments: >
-location: $(location)
-name: $(name)
-env: $(branchName)
errorActionPreference: 'continue'
azurePowerShellVersion: 'LatestVersion'
- task: ArchiveFiles@2
displayName: 'Zip up assets'
inputs:
rootFolderOrFile: 'heroImages'
includeRootFolder: false
archiveType: 'zip'
archiveFile: '$(Build.ArtifactStagingDirectory)/$(Build.BuildId).zip'
replaceExistingArchive: true
- task: PublishBuildArtifacts@1
displayName: 'Publish zipped assets for deployment'
inputs:
PathtoPublish: '$(Build.ArtifactStagingDirectory)/$(Build.BuildId).zip'
ArtifactName: 'drop'
publishLocation: 'Container'
Keep in mind this will not deploy anything, it will simply get it ready for deployment, if you do push this new YAML file, go to the job once it's finished you can click on the artifact created, download it and inspect it to see the contents of your heroImages folder.
That's is for this post, in the next one we'll set up the Continuous Deployment part of our CICD pipeline, that's where we will move our images into our azure Blob storage.