Skip to content

Latest commit

 

History

History
107 lines (64 loc) · 4.75 KB

lab5.md

File metadata and controls

107 lines (64 loc) · 4.75 KB

Lab 5 - CI and CD

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.

5.1 Build pipelines and artifacts

Let us start with a build pipeline that creates and publishes build artifacts for us.

  1. Goto Repos > Branches

  2. Create a new branch "lab5" that is based on master

  3. Goto Pipelines > Pipelines

  4. Click on "New pipeline"

  5. Click on "Azure Repos Git (YAML)"

  6. Select our repository

  7. Select "Existing Azure Pipelines YAML file"

    • Select the lab5 branch
    • Paste labs/lab5/examples/build.pipeline.yaml
  8. 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

    build pipeline example

  9. Click on "Run"

  10. Click on "Job" to check the job details

  11. Check the "CopyFiles" task

    You will see that our CopyFiles task found 1 file and copied it into out staging directory.

    build pipeline output

  12. 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.

    build pipeline output

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:

build pipeline output status

You can click on it to see in details which files where published.

build pipeline artifacts

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:

pipeline definition id

We need this definitionId to reference to our build pipeline as part of our next task.

5.2 Working with build artifacts

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.

  1. Goto Pipelines > Pipelines

  2. Click "New pipeline"

  3. Select "Azure Repos Git (YAML)"

  4. Select our repository

  5. Select "Existing AZure Pipelines YAML file"

  6. Select the correct branch (lab5)

  7. Paste the path /labs/lab5/examples/release.pipeline.yaml

  8. Click on "Continue"

    You will now see our example release pipeline:

    review 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.

  9. Update the buildPipelineDefinitionId with the definitionId from our previous task.

  10. Click on "Save and run" (twice)

  11. 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:

review release output

And an example where we execute a script that is coming from our artifacts:

review release output

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.