Beruflich Dokumente
Kultur Dokumente
Pipeline
Accessing Microsoft Azure
Launch Chrome from the virtual machine desktop and navigate to the URL below. Your
Azure Credentials are available by clicking the Cloud Icon at the top of the Lab Player.
zoom code
copy code
https://portal.azure.com
zoom code
copy code
https://dev.azure.com
2. Click the Start free button and then enter the credentials made available by
clicking on the Cloud Icon at the top of the Lab Player.
4. In the same Chrome browser tab, navigate to the link below. This utility site will
automate the process of creating a new project within your newly created Azure
DevOps account that is pre-populated with content (work items, repos, etc.)
required for this lab.
zoom code
copy code
https://azuredevopsdemogenerator.azurewebsites.net
5. Click Sign In and, if asked, use the same credentials made available by clicking on
the Cloud Icon at the top of the Lab Player.
zoom image
6. If you are presented with a We need a few more details screen, feel free to
update the Your name field, but it’s not required. Click Continue.
zoom image
8. Select your Azure DevOps organization and enter the project name “Parts
Unlimited”. Click Choose Template.
zoom image
zoom image
10. Click Create Project and wait for the process to complete. This can take a couple
minutes.
zoom image
zoom image
Exercise 3: Configuring Visual Studio Code
In this exercise, you’ll configure a Git credential helper to securely store the Git
credentials to communicate with Azure DevOps.
zoom code
copy code
zoom code
copy code
zoom code
copy code
zoom image
3. Click Clone.
zoom image
4. Click the Copy to clipboard button next to the repo clone URL. You can plug this
URL into any Git-compatible tool to get a copy of the codebase.
zoom image
5. Return to Visual Studio Code.
7. Execute the Git: Clone command. It may help to type “Git” to bring it into the
shortlist.
zoom code
copy code
>Git: Clone
zoom image
zoom image
11. Once the cloning has completed, click Open in the bottom right corner. You can
ignore any warnings raised about opening the projects. The solution may not be
in a buildable state, but that’s okay since we’re going to focus on working with
Git and building the project itself.
zoom image
Task 2: Installing the Azure Repos extension for Visual Studio Code
1. The Azure Repos extension provides convenient access to many features of Azure
DeVOps. From the Extensions tab, search for “Azure Repos” and click Install to
install it.
zoom image
zoom image
3. Press Ctrl+Shift+P to show the Command Palette.
4. Search for “>Team” to see all the new commands that are now available for
working with Azure Repos. Select Team: Signin.
zoom image
zoom image
6. Copy the provided token and press Enter to launch a browser tab.
zoom image
zoom image
What’s in a commit?
Git commits consist of the following: - The file(s) changed in the commit. Git keeps the
contents of all file changes in your repo in the commits. This keeps it fast and allows for
intelligent merging. - A reference to the parent commit(s). Git manages your code
history using these references. - A message describing a commit. You give this message
to Git when you create the commit. It’s a good idea to keep this message descriptive,
but to the point.
zoom image
2. Add a comment to the file. It doesn’t really matter what the comment is since the
goal is to simply make a change. Press Ctrl+S to save the file.
zoom image
zoom image
zoom image
5. If asked whether you would like to automatically stage your changes and commit
them directly, click Always. We will cover staging later in the lab.
zoom image
6. Click the Synchronize Changes button at the bottom left to sync your changes
with the server. Confirm the sync if prompted.
zoom image
zoom image
zoom image
Task 3: Staging changes
Staging changes allows you to selectively add certain files to a commit while passing
over the changes made in other files.
2. Update the open CartItem.cs class by editing the comment you made earlier and
saving the file.
zoom image
3. Open Category.cs as well.
zoom image
4. Add a new comment to Category.cs so there will be two files with changes. Save
the files.
zoom image
zoom image
zoom image
zoom image
Git’s use of the Branches and Merges feature works through pull requests, so the
commit history of your development doesn’t necessarily form a string, chronological
line. When you use history to compare versions, think in terms of file changes between
two commits instead of file changes between two points in time. A recent change to a
file in the master branch may have come from a commit created two weeks ago in a
feature branch but was only merged yesterday.
zoom image
2. A comparison view is opened to enable you to easily locate the changes you’ve
made. In this case, it’s just the one comment.
zoom image
zoom image
5. Note the history of Category.cs. Close the newly created window, and return to
the Commits tab from earlier. You may have to click Commits.
zoom image
zoom image
7. From the dropdown for Merged PR 27, select Browse Files.
zoom image
8. This view offers the ability to navigate around the state of the source code at that
commit so you can review and download those files.
zoom image
Exercise 7: Working with branches
You can manage the work in your Azure DevOps Git repo from the Branches view on
the web. You can also customize the view to track the branches you care most about so
you can stay on top of changes made by your team.
Committing changes to a branch will not affect other branches and you can share
branches with others without having to merge the changes in to the main project. You
can also create new branches to isolate changes for a feature or a bug fix from your
master branch and other work.
Since the branches are lightweight, switching between branches is quick and easy. Git
does not create multiple copies of your source when working with branches, but rather
uses the history information stored in commits to recreate the files on a branch when
you start working on it. Your Git workflow should create and use branches for managing
features and bug fixes. The rest of the Git workflow, such as sharing code and reviewing
code with pull requests, all work through branches. Isolating work in branches makes it
very simple to change what you are working on by simply changing your current branch.
zoom image
zoom image
4. Enter the name “dev” for the new branch and press Enter.
zoom image
zoom image
zoom image
zoom image
zoom image
3. You should see the newly pushed dev branch. Click the Delete branch button to
delete it. Confirm the delete.
zoom image
5. Click the dev branch.
zoom image
6. Note that there are two dev branches listed. The local (dev) branch is there
because it’s not deleted when the server branch is deleted. The server
(origin/dev) is there because it hasn’t been pruned. Select the master branch to
check it out.
zoom image
zoom image
zoom image
zoom image
11. Note that the local dev branch is gone, but the remote origin/dev is still
showing.
zoom image
13. Start typing “>Git: Fetch” and select Git: Fetch (Prune) when it becomes visible.
This command will update the origin branches in teh local snapshot and delete
those that are no longer there.
zoom image
14. You can check in on exactly what these tasks are doing by selecting
the Output window at the bottom of the screen. You may have to click View >
Output in the top tool bar to see it.
zoom image
15. Note that if you don’t see the Git logs in the output console, you may need to
select Git as the source.
zoom image
zoom image
zoom image
zoom image
3. Enter a name of “release” for the new branch. Use the Work items to
link dropdown to select one or more work items to link to this new branch.
Click Create branch to create it.
zoom image
4. After the branch has been created, it will be available on the list.
zoom image
5. Return to Visual Studio Code.
7. Start typing “>Git: Fetch” and select Git: Fetch when it becomes visible. This
command will update the origin branches in the local snapshot.
zoom image
8. Click the master branch.
zoom image
9. Select origin/release. This will create a new local branch called “release” and
check it out.
zoom image
2. However, maybe we should keep it around for a little longer. From its context
menu, select Restore branch.
zoom image
Locking does not prevent cloning of a repo or fetching updates made in the branch into
your local repo. If you local a branch, share with your team the reason why and make
sure they know what to do to work with the branch after it’s unlocked.
zoom image
2. The branch is now locked.
zoom image
zoom image
Task 4: Tagging a release
1. White it may not seem like much, the product team has decided this version of
the site is exactly what’s needed for v1.1. In order to mark it as such, navigate to
the Tags tab.
zoom image
2. Click Create Tag.
zoom image
zoom image
4. You have now tagged the project at this release. You could tag commits for a
variety of reasons and Azure DevOps offers the flexibility to edit and delete them,
as well as manage their permissions.
zoom image
zoom image
2. Set the Repository name to “New Repo”. Note that you also have the option to
create a file named README.md. This would be the default markdown file that is
rendered when someone navigates to the repo root in a browser. Additionally,
you can pre-configure the repo with a .gitignore file. This file specifies which
files, based on naming patterns and/or path, it ignore from source control. There
are multiple templates available that include the common patterns and paths to
ignore based on the project type you are creating. Then, click Create.
zoom image
3. That’s it. Your repo is ready. You can now clone it with Visual Studio Code or your
tools of choice.
zoom image
Task 2: Deleting and renaming Git repos
1. Sometimes you’ll have a need to rename or delete a repo, which is just as easy.
Open Project settings on the bottom left.
zoom image
2. Select Repositories under Repos.
zoom image
zoom image
4. Enter the name “New Repo” to confirm the repo delete and click Delete.
zoom image
Summary
Congratulations! You have learned how to manage version control with Git using Visual
Studio Code and Azure DevOps.
Lab Guide
Configuring CI/CD Pipelines Pipelines as Code with YAML in Azure DevOps
Overview
Many teams prefer to define their build and release pipelines using YAML (Yet Another
Markup Language). This allows them to access the same pipeline features as those using
the visual designer, but with a markup file that can be managed and controlled like any
other source file.
YAML build definitions can be added to a project by simply adding their source file to
the root of the repository. Azure DevOps also provides YAML templates for popular
project types, as well as a YAML designer which can simplify the process of defining
build and release tasks.
Learning Objectives
zoom code
copy code
https://portal.azure.com
Exercise 1: Configure Team Project
In this exercise, you’ll set up an Azure DevOps project and populate it with the Parts
Unlimited demo project files for us to use as a starting point.
zoom code
copy code
https://azuredevopsdemogenerator.azurewebsites.net/
This utility site will automate the process of creating a new Azure DevOps project
within your lab account that is pre-populated with content (work items, repos,
etc.) required for the lab.
zoom image
zoom image
Get Started for Free
zoom image
Get Started for Free
4. After your organization is created, navigate back to the Azure DevOps Demo
Generator using the url below and this time click Sign in.
zoom code
copy code
https://azuredevopsdemogenerator.azurewebsites.net/
zoom image
5. Click Accept at the prompt to grant the demo generator the necessary
permissions on your DevOps organization.
zoom image
zoom image
7. Back on the Create New Project page, click Create Project. Your project will
begin creating, and a progress bar will appear below the Create Project button.
zoom image
Summary
In this exercise, you created an Azure DevOps organization, as well as generated the
sample project we will use for the rest of the lab’s exercises
zoom code
copy code
https://portal.azure.com
2. Expand the navigation menu by clicking the Show portal menu button. Click +
Create a resource and search for then select “web app + sql”.
zoom image
zoom image
zoom image
3. Click Create.
zoom image
4. Enter a globally unique name for the app service. Select the option to Use
existing resource group named “SkillMeUpRG”.
zoom image
5. Click SQL Database to configure the database settings, then enter the Name
“partsunlimited”. This is the database our application will expect to connect to.
zoom image
6. Select Target server and enter a globally unique server name, such as “pul-
yaml-johndoe” and provide the following admin credentials:
zoom image
7. Next, select Configure pricing tier and then click the link: Looking for Basic,
Standard, Premium?.
zoom image
zoom image
9. Click Select to confirm the database settings.
zoom image
10. Finally, click Create to create the resources involved in our Web App + SQL
deployment.
zoom image
zoom code
copy code
https://dev.azure.com
2. Click your project then select Project Settings at the bottom left.
zoom image
3. In the left navigation under Pipelines, click Service Connections.
zoom image
4. Click Create Service Connection -> Azure Resource Manager -> Next.
zoom image
5. Click Service principal (automatic) -> Next.
zoom image
Task 3: Configuring the Parts Unlimited project
1. Navigate back to your Parts Unlimited team project in Azure DevOps.
2. Before digging into creating our YAML pipeline, let’s disable the existing build
pipeline which came with the demo content.
3. Navigate to Pipelines.
zoom image
4. Click on the name of the existing pipeline to open it. Then, click the ellipse
dropdown menu at the top right, and click Pause pipeline. We don’t want to
delete it, just prevent it from running.
zoom image
1. Navigate to the Pipelines hub.
zoom image
2. Click New Pipeline. We will use the wizard to automatically create the YAML
definition based on our project.
zoom image
3. Select the Azure Repos Git as the source hosting platform. Note that others are
supported.
zoom image
4. Select the PartsUnlimited repo.
zoom image
zoom image
6. Review the contents and structure of the YAML definition. As you can see from
the breadcrumb at the top, it will be saved as a new file called “azure-
pipelines.yml” in the root of the repository, and it contains everything needed to
build and test a typical ASP.NET solution.
You can also customize the build as needed. In this case, update the pool to
specify the build should use a Visual Studio 2017 build VM.
zoom code
copy code
zoom image
7. Next, you will modify the the msbuild arguments in the VSBuild task, to create
the output of the build in the artifactsStagingDirectory.
zoom image
Place your cursor on the new line and on the Tasks pane (you may have to
click Show Assistant) select Archive Files.
zoom image
Specify the following for Root folder - this is the location of the output to
archive:
zoom code
copy code
$(Build.ArtifactStagingDirectory)/_PublishedWebsites/partsUnlimitedWebsite
Make sure that the Archive file to create field looks like the below, this will
create a new zip with the build id as the filename.
zoom code
copy code
$(Build.ArtifactStagingDirectory)/$(Build.BuildId).zip
Ensure Replace existing archive is checked and click Add.
zoom image
Make sure your newly inserted YAML looks as shown in the screenshot. The Tasks
assistant indents based on where your cursor was, so if you were not on a blank
new line, you may need to make adjustments to match the below.
zoom image
10. In this YAML document we now have a build task, a test task, and an archive task
defined. Click Save and run.
zoom image
11. Click Save and run to confirm the commit of your updated .yml file to the project
repository. Add a description of your changes if you wish.
zoom image
12. Track the build until it completes. Each step will be shown, along with any
warnings or errors encountered. Your build should complete successfully, though
you will get a warning suggesting you further optimize by running operations
asynchronously.
13. You can click on your job to see each task from the YAML file, available for
review, including any warnings and errors, and how long each step took to
complete.
zoom image
zoom image
15. The tests should now reflect succeeded as expected. The default filters may only
show you failures and aborted tests. You can adjust these at the top right to see a
report similar to this screenshot.
zoom image
Task 5: Adding continuous delivery to the YAML definition
1. Now that the build and test processes are successful, we can now add continuous
delivery to our YAML definition. From our new pipeline’s overview, select Edit
pipeline.
zoom image
zoom code
copy code
stages:
- stage: Build
jobs:
- job: Build
zoom image
3. Highlight everything in the YAML file after your new stages section, and indent it
four spaces by pressing tab twice. This will simply take the existing build
definition and relocated it as a child of the jobs node.
zoom image
4. At the bottom of the file, on a new unindented line, add the configuration below
to define a separate Deploy stage stage.
zoom code
copy code
- stage: Deploy
jobs:
- job: Deploy
steps:
zoom image
5. Set the cursor on a new line at the end of the YAML definition. This will be the
location where new tasks are added.
zoom image
zoom image
7. Select the Azure service connection you created earlier. Then update the package
or folder setting tp the following value:
zoom code
copy code
$(System.ArtifactsDirectory)/**/$(Build.BuildId).zip
zoom image
8. Click Add. The YAML that defines the task will be added to the cursor location in
the file. With the added task still selected in the editor, indent it four spaces (two
tabs) so that it is a child of the steps task.
zoom image
9. It’s important to note that these two stages will be run independently. As a result,
the build output from the first stage will not be available to the second stage
without special consideration. For this, we will use one task to publish the build
output at the end of the build stage and another to download it in the beginning
of the deploy stage. Place the cursor on a blank line at the end of the build stage.
zoom image
10. Search the tasks for “publish build” and select the Publish Build Artifacts task.
There may be more than one available, so be sure to select the one that is not
deprecated.
zoom image
11. Accept the defaults and click Add. This will publish the build artifacts to a
location that will be downloadable under the alias drop.
zoom image
12. Just as we did with the original build steps, indent the new publish task four
spaces (two tabs) to make it a child of the build stage. You may also want to add
an empty line before and after to make it easier to read.
zoom image
zoom image
14. Search the tasks for “download build” and select the Download Build
Artifacts task.
zoom image
15. The Download build artifacts will not populate with the “drop” artifact you just
created automatically. You can type it in, or leave it blank and add it, which we’ll
describe in the next step. Click Add
zoom image
16. Make a new line after ‘single’, and add the following text in the YAML to point at
the artifact alias we created previously. Ensure your indentation matches the
previous line.
zoom code
copy code
artifactName: 'drop'
zoom image
17. Click Save to commit the changes.
zoom image
18. Confirm the Save. Because this is updating our repository, this will begin a new
build automatically.
zoom image
zoom image
20. Open the pipeline to view it’s current build status.
zoom image
zoom image
3. Select the Configuration tab.
zoom image
4. Click the defaultConnection setting.
zoom image
zoom image
6. Click Save to apply the changes.
zoom image
7. Return to the Overview tab.
zoom image
zoom image
10. Congratulations! You just defined a pipeline using YAML and deployed an
application using Azure DevOps.