Skip to content

Commit 456c03f

Browse files
committed
Branch name in pipeline trigger
Fix for error: Commit xxx is either not present in GitHub repository
1 parent 6fe5349 commit 456c03f

6 files changed

Lines changed: 34 additions & 0 deletions

File tree

.github/workflows/cicd-1-pull-request.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ jobs:
3434
with:
3535
environments: '["review"]'
3636
commit_sha: ${{ github.event.pull_request.head.sha }}
37+
branch_name: ${{ github.event.pull_request.head.ref }}
3738
secrets: inherit
3839

3940
# Build and publish a pre-release when the 'deploy' label is present.
@@ -58,4 +59,5 @@ jobs:
5859
environments: '["review"]'
5960
release_tag: pr-${{ github.event.pull_request.number }}
6061
commit_sha: ${{ github.event.pull_request.head.sha }}
62+
branch_name: ${{ github.event.pull_request.head.ref }}
6163
secrets: inherit

.github/workflows/cicd-2-main-branch.yaml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,7 @@ jobs:
134134
with:
135135
environments: '["dev"]'
136136
commit_sha: ${{ github.sha }}
137+
branch_name: ${{ github.ref_name }}
137138
secrets: inherit
138139

139140
deploy-app-dev:
@@ -147,6 +148,7 @@ jobs:
147148
environments: '["dev"]'
148149
release_tag: ${{ needs.resolve.outputs.release_tag }}
149150
commit_sha: ${{ github.sha }}
151+
branch_name: ${{ github.ref_name }}
150152
secrets: inherit
151153

152154
# ---- preprod --------------------------------------------------------------
@@ -164,6 +166,7 @@ jobs:
164166
with:
165167
environments: '["preprod"]'
166168
commit_sha: ${{ github.sha }}
169+
branch_name: ${{ github.ref_name }}
167170
secrets: inherit
168171

169172
deploy-app-preprod:
@@ -180,6 +183,7 @@ jobs:
180183
environments: '["preprod"]'
181184
release_tag: ${{ needs.resolve.outputs.release_tag }}
182185
commit_sha: ${{ github.sha }}
186+
branch_name: ${{ github.ref_name }}
183187
secrets: inherit
184188

185189
# ---- review (manual only) -------------------------------------------------
@@ -194,6 +198,7 @@ jobs:
194198
with:
195199
environments: '["review"]'
196200
commit_sha: ${{ github.sha }}
201+
branch_name: ${{ github.ref_name }}
197202
secrets: inherit
198203

199204
deploy-app-review:
@@ -207,4 +212,5 @@ jobs:
207212
environments: '["review"]'
208213
release_tag: ${{ needs.resolve.outputs.release_tag }}
209214
commit_sha: ${{ github.sha }}
215+
branch_name: ${{ github.ref_name }}
210216
secrets: inherit

.github/workflows/cicd-3-release.yaml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ jobs:
4242
environment: dev
4343
release_tag: ${{ github.ref_name }}
4444
commit_sha: ${{ github.sha }}
45+
branch_name: main
4546
secrets: inherit
4647

4748
deploy-preprod:
@@ -52,6 +53,7 @@ jobs:
5253
environment: preprod
5354
release_tag: ${{ github.ref_name }}
5455
commit_sha: ${{ github.sha }}
56+
branch_name: main
5557
secrets: inherit
5658

5759
prod-approval:
@@ -71,4 +73,5 @@ jobs:
7173
environment: prod
7274
release_tag: ${{ github.ref_name }}
7375
commit_sha: ${{ github.sha }}
76+
branch_name: main
7477
secrets: inherit

.github/workflows/stage-4-deploy-app.yaml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,11 @@ on:
1515
description: Commit SHA used to trigger the ADO pipeline
1616
required: true
1717
type: string
18+
branch_name:
19+
description: Git branch containing commit_sha
20+
required: false
21+
default: "main"
22+
type: string
1823

1924
jobs:
2025
deploy:
@@ -46,13 +51,16 @@ jobs:
4651
ENVIRONMENT: ${{ matrix.environment }}
4752
RELEASE_TAG: ${{ inputs.release_tag }}
4853
COMMIT_SHA: ${{ inputs.commit_sha }}
54+
BRANCH_NAME: ${{ inputs.branch_name }}
4955
ADO_PROJECT: ${{ github.event.repository.name }}
5056
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
5157
run: |
5258
source "infrastructure/environments/${ENVIRONMENT}/variables.sh"
59+
SOURCE_BRANCH="${BRANCH_NAME:-main}"
5360
5461
echo "Starting Azure DevOps pipeline \"Deploy Gateway App - ${ENVIRONMENT}\"..."
5562
RUN_ID=$(az pipelines run \
63+
--branch "${SOURCE_BRANCH}" \
5664
--commit-id "${COMMIT_SHA}" \
5765
--name "Deploy Gateway App - ${ENVIRONMENT}" \
5866
--org https://dev.azure.com/nhse-dtos \

.github/workflows/stage-4-deploy-env.yaml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,11 @@ on:
1515
description: Commit SHA used to trigger the ADO pipeline
1616
required: true
1717
type: string
18+
branch_name:
19+
description: Git branch containing commit_sha
20+
required: false
21+
default: "main"
22+
type: string
1823

1924
jobs:
2025
deploy-infra:
@@ -25,6 +30,7 @@ jobs:
2530
with:
2631
environments: '["${{ inputs.environment }}"]'
2732
commit_sha: ${{ inputs.commit_sha }}
33+
branch_name: ${{ inputs.branch_name }}
2834
secrets: inherit
2935

3036
deploy-app:
@@ -37,6 +43,7 @@ jobs:
3743
environments: '["${{ inputs.environment }}"]'
3844
release_tag: ${{ inputs.release_tag }}
3945
commit_sha: ${{ inputs.commit_sha }}
46+
branch_name: ${{ inputs.branch_name }}
4047
secrets: inherit
4148

4249
smoke-test:

.github/workflows/stage-4-deploy.yaml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,11 @@ on:
1111
description: Commit SHA used to trigger the ADO pipeline
1212
required: true
1313
type: string
14+
branch_name:
15+
description: Git branch containing commit_sha
16+
required: false
17+
default: "main"
18+
type: string
1419

1520
jobs:
1621
deploy:
@@ -41,12 +46,15 @@ jobs:
4146
env:
4247
ENVIRONMENT: ${{ matrix.environment }}
4348
COMMIT_SHA: ${{ inputs.commit_sha }}
49+
BRANCH_NAME: ${{ inputs.branch_name }}
4450
ADO_PROJECT: ${{ github.event.repository.name }}
4551
run: |
4652
source "infrastructure/environments/${ENVIRONMENT}/variables.sh"
53+
SOURCE_BRANCH="${BRANCH_NAME:-main}"
4754
4855
echo "Starting Azure devops pipeline \"Deploy to Azure - ${ENVIRONMENT}\"..."
4956
RUN_ID=$(az pipelines run \
57+
--branch "${SOURCE_BRANCH}" \
5058
--commit-id "${COMMIT_SHA}" \
5159
--name "Deploy to Azure - ${ENVIRONMENT}" \
5260
--org https://dev.azure.com/nhse-dtos \

0 commit comments

Comments
 (0)