Skip to content

Commit 66ae8f0

Browse files
[feat] added condition on push step
1 parent 2bd138b commit 66ae8f0

File tree

1 file changed

+4
-3
lines changed

1 file changed

+4
-3
lines changed

content/guides/azure-pipelines.md

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,6 @@ variables:
6060
stages:
6161
- stage: BuildAndPush
6262
displayName: Build and Push Docker Image
63-
condition: and(succeeded(), eq(variables['Build.SourceBranch'], 'refs/heads/main'))
6463
jobs:
6564
- job: DockerJob
6665
displayName: Build and Push
@@ -94,6 +93,7 @@ stages:
9493

9594
- task: Docker@2
9695
displayName: Push Docker Image
96+
condition: eq(variables['Build.SourceBranch'], 'refs/heads/main')
9797
inputs:
9898
command: push
9999
repository: $(imageName)
@@ -163,12 +163,10 @@ These variables ensure consistent naming, versioning, and reuse throughout the p
163163
stages:
164164
- stage: BuildAndPush
165165
displayName: Build and Push Docker Image
166-
condition: and(succeeded(), eq(variables['Build.SourceBranch'], 'refs/heads/main'))
167166
```
168167

169168
This stage executes only if:
170169

171-
- The pipeline completes successfully.
172170
- The source branch is main.
173171

174172
> [!TIP]
@@ -258,6 +256,7 @@ This builds the image with:
258256
```yaml
259257
- task: Docker@2
260258
displayName: Push Docker Image
259+
condition: eq(variables['Build.SourceBranch'], 'refs/heads/main')
261260
inputs:
262261
command: push
263262
repository: $(imageName)
@@ -266,10 +265,12 @@ This builds the image with:
266265
$(latestTag)
267266
268267
```
268+
By applying this condition, the pipeline builds the Docker image on every run to ensure early detection of issues, but only pushes the image to the registry when changes are merged into the main branch—keeping your Docker Hub clean and focused
269269

270270
This uploads both tags to Docker Hub:
271271
- `$(buildTag)` ensures traceability per run.
272272
- `latest` is used for most recent image references.
273+
-
273274

274275

275276
#### Step 4.5 Logout from Docker (Self-Hosted Agents)

0 commit comments

Comments
 (0)