Skip to content

Commit 4023023

Browse files
fix: handle missing DockerHub/SonarQube secrets gracefully in CI
- Skip Docker buildx/push steps when DOCKERHUB_USERNAME secret is not set - Fall back to plain docker build (no push) when secrets are missing - Fix SonarQube conditionals to use secrets context directly Co-Authored-By: vanessa.salas <vanessa.salas@cognition.ai>
1 parent 37259c0 commit 4023023

1 file changed

Lines changed: 11 additions & 5 deletions

File tree

.github/workflows/ci.yml

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ jobs:
6363
path: reports/
6464

6565
- name: SonarQube Analysis
66-
if: ${{ env.SONAR_TOKEN != '' }}
66+
if: ${{ secrets.SONAR_TOKEN != '' }}
6767
uses: SonarSource/sonarqube-scan-action@v5
6868
env:
6969
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
@@ -74,7 +74,7 @@ jobs:
7474
-Dsonar.projectName=bankapp
7575
7676
- name: SonarQube Quality Gate
77-
if: ${{ env.SONAR_TOKEN != '' }}
77+
if: ${{ secrets.SONAR_TOKEN != '' }}
7878
uses: SonarSource/sonarqube-quality-gate-action@v1
7979
timeout-minutes: 5
8080
env:
@@ -91,26 +91,32 @@ jobs:
9191
fi
9292
9393
- name: Set up Docker Buildx
94+
if: ${{ secrets.DOCKERHUB_USERNAME != '' }}
9495
uses: docker/setup-buildx-action@v3
9596

9697
- name: Login to DockerHub
97-
if: ${{ env.DOCKERHUB_USERNAME != '' }}
98+
if: ${{ secrets.DOCKERHUB_USERNAME != '' }}
9899
uses: docker/login-action@v3
99100
with:
100101
username: ${{ secrets.DOCKERHUB_USERNAME }}
101102
password: ${{ secrets.DOCKERHUB_TOKEN }}
102103

103104
- name: Build and Push Docker Image
105+
if: ${{ secrets.DOCKERHUB_USERNAME != '' }}
104106
uses: docker/build-push-action@v6
105107
with:
106108
context: .
107-
push: ${{ env.DOCKERHUB_USERNAME != '' && github.event_name != 'pull_request' }}
109+
push: ${{ github.event_name != 'pull_request' }}
108110
tags: |
109111
${{ secrets.DOCKERHUB_USERNAME }}/${{ env.IMAGE_NAME }}:${{ steps.docker-tag.outputs.tag }}
110112
${{ secrets.DOCKERHUB_USERNAME }}/${{ env.IMAGE_NAME }}:latest
111113
114+
- name: Build Docker Image (no push)
115+
if: ${{ secrets.DOCKERHUB_USERNAME == '' }}
116+
run: docker build -t ${{ env.IMAGE_NAME }}:${{ steps.docker-tag.outputs.tag }} .
117+
112118
- name: Trigger CD Workflow
113-
if: success() && github.event_name != 'pull_request' && env.DOCKERHUB_USERNAME != ''
119+
if: success() && github.event_name != 'pull_request' && secrets.DOCKERHUB_USERNAME != ''
114120
uses: peter-evans/repository-dispatch@v3
115121
with:
116122
event-type: deploy

0 commit comments

Comments
 (0)