Creating a build pipeline - varoonsahgal/tf-az-wt GitHub Wiki
💻 Lab: Create a Build Pipeline and Publish Artifacts
🎯 Objective
Create a simple build pipeline in Azure DevOps Classic UI that:
- Clones a GitHub repo
- Builds a basic Java application
- Publishes build artifacts
🧰 Prerequisites
0. Read here for diff between Azure DevOps and Azure Portal:
https://github.com/varoonsahgal/tf-az-wt/wiki/Azure-DevOps-vs-Azure-Portal
Read here on how to setup billing for your pipeline: https://github.com/varoonsahgal/tf-az-wt/wiki/Azure-DevOps-Pipelines-Billing-Setup
1. Azure DevOps Account Setup
If you don’t already have an Azure DevOps account:
-
Go to: https://dev.azure.com/
-
Sign in with your Microsoft account (or create one)
-
When prompted, create a new Azure DevOps Organization
- Use a unique name like:
yourname-devops-org
:
- Use a unique name like:
2. Create a New Azure DevOps Project
- Inside your DevOps Organization, click New Project
- Name the project:
PipelineDemo
- Set Visibility to Private
- Click Create
3. **Enable Classic Editor **
-
The Classic Editor is not visible by default. To enable it:
-
In the bottom-left corner, click ⚙️ Organization settings
-
In the left-hand menu, under Pipelines, click Settings
-
Look for the options:
✅ “Disable creation of classic build pipelines” ✅ “Disable creation of classic release pipelines”
- Make sure these options are unchecked
- This will enable the “Use the classic editor” link when creating new build and release pipelines.
Lab instructions here:
Select Github here:
Be sure to import my sample Github repo first. Importing is a quick way to create YOUR own copy of a repository. You can go here to import a repository:
To import a repo go to: https://github.com/new/import
Then where it says The URL for your source repository
you can put in my starter repository here: https://github.com/varoonsahgal/azure-devops-starter.git
No need for username/password fields - but do give the repository a name and leave it public as well.
Select your repo:
Select show more:
Then scroll down and select Maven since that's the framework we are using.
Then you will see this page with some yaml:
Above, Pool represents the Operating System that will be used on a machine that Azure sets up for you. Why does Azure set up a machine for you? To run the build in the cloud - this way you do not have to run the build locally
Why does it say goals: 'package'
? basically this is a Maven "thing" that creates the build artifact for you - the WAR file in this case. This basically creates the same artifact as mvn clean install
.
Go ahead and click on Save on the top right, by clicking on the down arrow:
The yaml file that you see above will get added to your Git repository onto your main branch, which you can check by going to the repository and refreshing.
Remember: the yaml file is KEY! it is what Azure looks at to figure out how to build your code and bundle/package it into a BUILD ARTIFACT.
Next, select Run pipeline:
And just go with the defaults:
Click on Job at the bottom:
This will show you the details of the build that Azure ran on your behalf:
You should see after 1 minute or so (maybe earlier) that the job finishes. The checkout step is where it clones your git repo to a build machine. mvn step is where it runs the actual build for Maven on that same build machine:
This is where it stores the war file locally on the agent build machine. This is called an "agent" machine because like an agent in the real world it acts on your behalf - running the build FOR YOU instead of you running it yourself.
The war file is created in this directory by Azure, where "s" stands for source code /home/vsts/work/1/s/webapp/target/webapp.war :
Now that we have a WAR file we just want to put into a Tomcat WEB Server so that we can show off our beautiful hello world application. But to do that we must take the WAR file which is currently just built on an Azure build machine, and move it into the portal so that we can then deploy it
Right now we only have 0 artifacts showing up in our pipeline:
We have to edit our pipeline to do this, so go to Pipelines on the left hand menu, select your pipeline, then you should see an edit button on the top right, go ahead and click on it:
then you should see your yaml file. Then, in the right where it says tasks search for copy and select "Copy files" - the 2nd option:
For target folder select put in $(build.artifactstagingdirectory) and for contents put it **/*.war, you can leave source folder blank because it will just find the WAR file in any child folder and then copy it:
Note the screenshot has **/.war, but it should be **/*.war:
Then, put your cursor at the last line in the YAML file and click add:
Result should look like this:
Next we have to publish - search for publish build artifacts:
Put in warfile, and select Add:
Click Validate and Save, and then Save.
Go to your pipeline and then run it, if it does not start running automatically for you...
Click on the job:
After it runs you should see 1 published under related, which means that the build artifact was created with success! So we have extracted the artifact from the Ubuntu build machine and brought it into our Azure pipelines:
Click on 1 published and you will see this:
Also you can see a couple of tests ran as well:
Note that Continuous Integration is actually built into this project - wherein it will automatically run the pipeline whenever any code is changed! This is because of the trigger section in the yaml file.