You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: content/guides/azure-pipelines.md
+29-23Lines changed: 29 additions & 23 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -12,7 +12,7 @@ params:
12
12
13
13
## Prerequisites
14
14
15
-
Before you begin, ensure the following requirements are met:
15
+
Before you begin, ensure you have the following requirements:
16
16
17
17
- A [Docker Hub account](https://hub.docker.com) with a generated access token.
18
18
- An active [Azure DevOps project](https://dev.azure.com/) with a connected [Git repository](https://learn.microsoft.com/en-us/azure/devops/repos/git/?view=azure-devops).
@@ -30,12 +30,13 @@ This guide walks you through building and pushing Docker images using [Azure Pip
30
30
To securely authenticate with Docker Hub using Azure Pipelines:
31
31
32
32
1. Navigate to **Project Settings > Service Connections** in your Azure DevOps project.
33
-
2.Click**New service connection > Docker Registry**.
33
+
2.Select**New service connection > Docker Registry**.
34
34
3. Choose **Docker Hub** and provide your Docker Hub credentials or access token.
35
35
4. Give the service connection a recognizable name, such as `my-docker-registry`.
36
36
5. Grant access only to the specific pipeline(s) that require it for improved security and least privilege.
37
37
38
38
> [!IMPORTANT]
39
+
>
39
40
> Avoid selecting the option to grant access to all pipelines unless absolutely necessary. Always apply the principle of least privilege.
40
41
41
42
## Step 2: Create your pipeline
@@ -120,9 +121,9 @@ This pipeline automates the Docker image build and deployment process for the ma
120
121
- Logs out from Docker if running on a self-hosted Linux agent.
121
122
122
123
123
-
## Detailed Step-by-Step Explanation
124
+
## How the pipeline works
124
125
125
-
### Step 1: Define Pipeline Triggers
126
+
### Step 1: Define pipeline triggers
126
127
127
128
```yaml
128
129
trigger:
@@ -139,7 +140,7 @@ This pipeline is triggered automatically on:
139
140
> [!TIP]
140
141
> Learn more: [Define pipeline triggers in Azure Pipelines](https://learn.microsoft.com/en-us/azure/devops/pipelines/build/triggers?view=azure-devops)
141
142
142
-
### Step 2: Define Common Variables
143
+
### Step 2: Define common variables
143
144
144
145
```yaml
145
146
variables:
@@ -155,30 +156,30 @@ These variables ensure consistent naming, versioning, and reuse throughout the p
155
156
- `latestTag`: a stable alias for your most recent image
156
157
157
158
> [!IMPORTANT]
159
+
>
158
160
> The variable `dockerUsername` is not set automatically.
159
161
> Set it securely in your Azure DevOps pipeline variables:
160
-
> 1. Go to **Pipelines > Edit > Variables**
161
-
> 2. Add `dockerUsername` with your Docker Hub username
162
+
> 1. Go to **Pipelines > Edit > Variables**
163
+
> 2. Add `dockerUsername` with your Docker Hub username
162
164
>
163
165
> Learn more: [Define and use variables in Azure Pipelines](https://learn.microsoft.com/en-us/azure/devops/pipelines/process/variables?view=azure-devops&tabs=yaml%2Cbatch)
164
166
165
-
### Step 3: Define Pipeline Stages and Jobs
167
+
### Step 3: Define pipeline stages and jobs
166
168
167
169
```yaml
168
170
stages:
169
171
- stage: BuildAndPush
170
172
displayName: Build and Push Docker Image
171
173
```
172
174
173
-
This stage executes only if:
174
-
175
-
- The source branch is main.
175
+
This stage executes only if the source branch is `main`.
176
176
177
177
> [!TIP]
178
+
>
178
179
> Learn more: [Stage conditions in Azure Pipelines](https://learn.microsoft.com/en-us/azure/devops/pipelines/process/stages?view=azure-devops&tabs=yaml)
179
180
180
181
181
-
### Step 4: Job Configuration
182
+
### Step 4: Job configuration
182
183
183
184
```yaml
184
185
jobs:
@@ -193,9 +194,10 @@ jobs:
193
194
This job utilizes the latest Ubuntu VM image with Docker support, provided by Microsoft-hosted agents. It can be replaced with a custom pool for self-hosted agents if necessary.
194
195
195
196
> [!TIP]
197
+
>
196
198
> Learn more: [Specify a pool in your pipeline](https://learn.microsoft.com/en-us/azure/devops/pipelines/agents/pools-queues?view=azure-devops&tabs=yaml%2Cbrowser)
197
199
198
-
#### Step 4.1 Checkout Code
200
+
#### Step 4.1: Checkout code
199
201
200
202
```yaml
201
203
steps:
@@ -206,9 +208,10 @@ steps:
206
208
This step pulls your repository code into the build agent, so the pipeline can access the Dockerfile and application files.
@@ -218,12 +221,13 @@ This step pulls your repository code into the build agent, so the pipeline can a
218
221
containerRegistry: 'my-docker-registry' # Replace with your service connection name
219
222
```
220
223
221
-
Uses a preconfigured Azure DevOps Docker registry service connection to authenticate securely without exposing credentials directly.
224
+
Uses a pre-configured Azure DevOps Docker registry service connection to authenticate securely without exposing credentials directly.
222
225
223
226
> [!TIP]
227
+
>
224
228
> Learn more: [Use service connections for Docker Hub](https://learn.microsoft.com/en-us/azure/devops/pipelines/library/service-endpoints?view=azure-devops#docker-hub-or-others)
225
229
226
-
#### Step 4.3 Build the Docker Image
230
+
#### Step 4.3: Build the Docker image
227
231
228
232
```yaml
229
233
- task: Docker@2
@@ -252,11 +256,12 @@ This builds the image with:
252
256
- Provenance attestation to verify how and where the image was built
253
257
254
258
> [!TIP]
259
+
>
255
260
> Learn more:
256
261
> - [Docker task for Azure Pipelines](https://learn.microsoft.com/en-us/azure/devops/pipelines/tasks/reference/docker-v2?view=azure-pipelines&tabs=yaml)
- Build images that meet modern software supply chain requirements with SBOM and attestation
297
303
298
-
## Further Reading
304
+
## Learn more
299
305
300
-
- [Azure Pipelines Documentation](https://learn.microsoft.com/en-us/azure/devops/pipelines/?view=azure-devops) - Comprehensive guide to configuring and managing CI/CD pipelines in Azure DevOps.
301
-
- [Docker Task for Azure Pipelines](https://learn.microsoft.com/en-us/azure/devops/pipelines/tasks/build/docker) - Detailed reference for using the Docker task in Azure Pipelines to build and push images.
302
-
- [Docker Buildx Bake](/manuals/build/bake/_index.md) - Explore Docker's advanced build tool for complex, multi-stage, and multi-platform build setups. See also the [Mastering Buildx Bake Guide](/guides/bake/index.md) for practical examples and best practices.
303
-
- [Docker Build Cloud](/guides/docker-build-cloud/_index.md) - Learn about Docker's managed build service for faster, scalable, and multi-platform image builds in the cloud.
306
+
- [Azure Pipelines Documentation](https://learn.microsoft.com/en-us/azure/devops/pipelines/?view=azure-devops):Comprehensive guide to configuring and managing CI/CD pipelines in Azure DevOps.
307
+
- [Docker Task for Azure Pipelines](https://learn.microsoft.com/en-us/azure/devops/pipelines/tasks/build/docker):Detailed reference for using the Docker task in Azure Pipelines to build and push images.
308
+
- [Docker Buildx Bake](/manuals/build/bake/_index.md):Explore Docker's advanced build tool for complex, multi-stage, and multi-platform build setups. See also the [Mastering Buildx Bake Guide](/guides/bake/index.md) for practical examples and best practices.
309
+
- [Docker Build Cloud](/guides/docker-build-cloud/_index.md):Learn about Docker's managed build service for faster, scalable, and multi-platform image builds in the cloud.
0 commit comments