Note
Access to this page requires authorization. You can try signing in or changing directories.
Access to this page requires authorization. You can try changing directories.
Azure DevOps Services | Azure DevOps Server | Azure DevOps Server 2022 | Azure DevOps Server 2020
Prerequisites
Initialize your repository
If you already have a repository in your project, you can skip to the next step: Skip to adding a script to your repo
In this tutorial, our focus is on CI/CD, so we're keeping the code part simple. We're working in an Azure Repos Git repository directly in your web browser.
When you're ready to begin building and deploying a real app, you can use a wide range of version control clients and services with Azure Pipelines CI builds. Learn more.
Create a build pipeline
Create a build pipeline that prints "Hello world."
A build pipeline is the entity through which you define your automated build pipeline. In the build pipeline, you compose a set of tasks, each of which perform a step in your build. The task catalog provides a rich set of tasks for you to get started. You can also add PowerShell or shell scripts to your build pipeline.
Publish an artifact from your build
A typical build produces an artifact that can then be deployed to various stages in a release. Here to demonstrate the capability in a simple way, we'll simply publish the script as the artifact.
Artifacts are the files that you want your build to produce. Artifacts can be nearly anything your team needs to test or deploy your app. For example, you've got a .DLL and .EXE executable files and .PDB symbols file of a C# or C++ .NET Windows app.
To enable you to produce artifacts, we provide tools such as copying with pattern matching, and a staging directory in which you can gather your artifacts before publishing them. See Artifacts in Azure Pipelines.
Enable continuous integration (CI)
Select the Triggers tab.
Enable Continuous integration.
A continuous integration trigger on a build pipeline indicates that the system should automatically queue a new build whenever a code change is committed. You can make the trigger more general or more specific, and also schedule your build (for example, on a nightly basis). See Build triggers.
Save and queue the build
Save and queue a build manually and test your build pipeline.
Add some variables and commit a change to your script
We'll pass some build variables to the script to make our pipeline a bit more interesting. Then we'll commit a change to a script and watch the CI pipeline run automatically to validate the change.
Edit your build pipeline.
On the Tasks tab, select the PowerShell script task.
Add these arguments.
Arguments
-greeter "$(Build.RequestedFor)" -trigger "$(Build.Reason)"
Finally, save the build pipeline.
Next you'll add the arguments to your script.
Go to your Files in Azure Repos (the Code hub in the previous navigation and TFS).
Select the HelloWorld.ps1 file, and then Edit the file.
Change the script as follows:
Param( [string]$greeter, [string]$trigger ) Write-Host "Hello world" from $greeter Write-Host Trigger: $triggerCommit (save) the script.
Select the new build that was created and view its log.
Notice that the person who changed the code has their name printed in the greeting message. You also see printed that this was a CI build.
We just introduced the concept of build variables in these steps. We printed the value of a variable that is automatically predefined and initialized by the system. You can also define custom variables and use them either in arguments to your tasks, or as environment variables within your scripts. To learn more about variables, see Build variables.
You've got a build pipeline. What's next?
You've created a build pipeline that automatically builds and validates whatever code is checked in by your team. At this point, you can continue to the next section to learn about release pipelines. Or, if you prefer, you can skip ahead to create a build pipeline for your app.
Create a release pipeline
Define the process for running the script in two stages.
A release pipeline is a collection of stages to which the application build artifacts are deployed. It also defines the actual deployment pipeline for each stage, as well as how the artifacts are promoted from one stage to another.
Also, notice that we used some variables in our script arguments. In this case, we used release variables instead of the build variables we used for the build pipeline.
Deploy a release
Run the script in each stage.
You can track the progress of each release to see if it has been deployed to all the stages. You can track the commits that are part of each release, the associated work items, and the results of any test runs that you've added to the release pipeline.
Change your code and watch it automatically deploy to production
We'll make one more change to the script. This time it will automatically build and then get deployed all the way to the production stage.
Go to the Code hub, Files tab, edit the HelloWorld.ps1 file, and change it as follows:
Param( [string]$greeter, [string]$trigger ) Write-Host "Hello world" from $greeter Write-Host Trigger: $trigger Write-Host "Now that you've got CI/CD, you can automatically deploy your app every time your team checks in code."Commit (save) the script.
Select the Builds tab to see the build queued and run.
After the build is completed, select the Releases tab, open the new release, and then go to the Logs.
Your new code automatically is deployed in the QA stage, and then in the Production stage.
In many cases, you probably would want to edit the release pipeline so that the production deployment happens only after some testing and approvals are in place. See Approvals and gates overview.
Next steps
You've learned the basics of creating and running a pipeline. Now you're ready to configure your build pipeline for the programming language you're using. Go ahead and create a new build pipeline, and this time, use one of the following templates.
| Language | Template to use |
|---|---|
| .NET | ASP.NET |
| .NET Core | ASP.NET Core |
| C++ | .NET Desktop |
| Go | Go |
| Java | Gradle |
| JavaScript | Node.js |
| Xcode | Xcode |
FAQ
Where can I read articles about DevOps and CI/CD?
What is Continuous Integration?
What version control system can I use?
When you're ready to get going with CI/CD for your app, you can use the version control system of your choice:
Clients
Services
- Azure Pipelines
- Git service providers such as GitHub and Bitbucket Cloud
- Subversion
You can edit and test your draft as needed.
When you're ready, you can publish the draft to merge the changes into your build pipeline.
Or, if you decide to discard the draft, you can delete it from the All Pipeline tab shown above.
How can I delete a pipeline?
To delete a pipeline, navigate to the summary page for that pipeline, and choose Delete from the ... menu in the top-right of the page. Type the name of the pipeline to confirm, and choose Delete.
You can queue builds automatically or manually.
When you manually queue a build, you can, for a single run of the build:
Specify the pool into which the build goes.
Add and modify some variables.
Add demands.
In a Git repository
In a TFVC repository
Run a private build of a shelveset. (You can use this option on either a Microsoft-hosted agent or a self-hosted agent.)