In this lab we are going to implement a build pipeline that creates versioned artifacts that can be used by multiple other release pipelines afterwards.
You can publish and consume many different types of packages and artifacts with Azure Pipelines. Your continuous integration/continuous deployment (CI/CD) pipeline can publish specific package types to their respective package repositories (NuGet, npm, Python, and so on). Or you can use build artifacts and pipeline artifacts to help store build outputs and intermediate files between build steps. You can then add onto, build, test, or even deploy those artifacts. Goto docs.microsoft.com to learn more.
Let us start with a build pipeline that creates and publishes build artifacts for us.
-
Goto Repos > Branches
-
Create a new branch "lab5" that is based on master
-
Goto Pipelines > Pipelines
-
Click on "New pipeline"
-
Click on "Azure Repos Git (YAML)"
-
Select our repository
-
Select "Existing Azure Pipelines YAML file"
- Select the lab5 branch
- Paste
labs/lab5/examples/build.pipeline.yaml
-
Click on "Continue"
You will now see a very simple build pipeline that does two things:
- Copy all files that end with *.sh (shell script)
- Publish these files as build artifacts
-
Click on "Run"
-
Click on "Job" to check the job details
-
Check the "CopyFiles" task
You will see that our CopyFiles task found 1 file and copied it into out staging directory.
-
Next, check the "PublishPipelineArtifact" task
You will see here that it has published 1 file. This is the file that was copied in the previous step.
With this we have now successfully created a build pipeline that takes a subset of files from our repository and publishes them as artifacts.
You can also find your build artifacts from within the Azure DevOps UI when you goto the pipeline run details:
You can click on it to see in details which files where published.
We will see in the next task how to work with these artifacts. Before we proceed, please take a note of the ID of our build pipeline:
We need this definitionId
to reference to our build pipeline as part of our next task.
In our previous task we have created a build pipeline that has copied a subset of files from a repository and published them as build artifacts.
We now want to consume these build artifacts to do something with them. Therefore we will now create a release pipeline.
-
Goto Pipelines > Pipelines
-
Click "New pipeline"
-
Select "Azure Repos Git (YAML)"
-
Select our repository
-
Select "Existing AZure Pipelines YAML file"
-
Select the correct branch (lab5)
-
Paste the path
/labs/lab5/examples/release.pipeline.yaml
-
Click on "Continue"
You will now see our example release pipeline:
The pipeline contains three main areas.
In 1) you see the variables definition. We are specifiying here the buildPipelineDefinitionId that contains the ID of our build pipeline (created in the previous task).
In 2) you see the
DownloadPipelineArtifact@2
task that is downloading our artifact that we have created in our build pipeline. There are more paramters to make this even more specific.In 3) you see how we execute a script that comes from our artifact.
-
Update the
buildPipelineDefinitionId
with the definitionId from our previous task. -
Click on "Save and run" (twice)
-
In our job details, click on "Job"
Here we will now find the Download Pipeline Artifacts
task that is downloading the artifacts from a specific build pipeline:
And an example where we execute a script that is coming from our artifacts:
And that was a short introduction into CI and CD (build and release) with a YAML-based pipeline in Azure DevOps.
This separation can be useful in many ways.
- Single Build, multiple Release (for example with a shared scripts or template repository)
- Versioning Artifacts like Templates and Scripts to release a specific version of it
This concludes Lab 5. Let's now go back to the Overview.