Skip to content

Commit 0058474

Browse files
IONOS(ci): Add prerequisites validation to trigger-remote-dev-workflow
Add comprehensive validation before triggering remote GitLab workflow: Dependency Management: - Add build-artifact to needs array to ensure NC_VERSION output is available - Update if condition to verify both build-artifact and upload-to-artifactory succeeded Variable Validation: - Validate secrets (GITLAB_TOKEN, GITLAB_TRIGGER_URL) - Validate job outputs (NC_VERSION, ARTIFACTORY_LAST_BUILD_PATH) - Validate GitHub context variables (sha, run_id, ref_name) - Abort with error if any required variable is missing This prevents the remote workflow from being triggered with missing critical variables like NC_VERSION, which was previously not available because build-artifact was not in the needs array. Signed-off-by: Misha M.-Kupriyanov <kupriyanov@strato.de>
1 parent 1b7e230 commit 0058474

File tree

1 file changed

+62
-1
lines changed

1 file changed

+62
-1
lines changed

.github/workflows/build-artifact.yml

Lines changed: 62 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -928,17 +928,78 @@ jobs:
928928
runs-on: self-hosted
929929

930930
name: Trigger remote workflow
931-
needs: [upload-to-artifactory]
931+
needs: [build-artifact, upload-to-artifactory]
932932
# Trigger remote build on "ionos-dev|ionos-stable|rc/*" branch *push* defined in the on:push:branches
933933
# Can be disabled via repository variable 'DISABLE_REMOTE_TRIGGER' (set to 'true' to disable)
934934
# Configure at: https://github.com/IONOS-Productivity/ncw-server/settings/variables/actions
935935
if: |
936936
always() &&
937937
github.event_name == 'push' &&
938938
(github.ref_name == 'ionos-dev' || github.ref_name == 'ionos-stable' || startsWith(github.ref_name, 'rc/')) &&
939+
needs.build-artifact.result == 'success' &&
939940
needs.upload-to-artifactory.result == 'success' &&
940941
vars.DISABLE_REMOTE_TRIGGER != 'true'
941942
steps:
943+
- name: Check prerequisites
944+
run: |
945+
echo "Checking if all required variables are set..."
946+
error_count=0
947+
948+
# Check secrets
949+
if [ -z "${{ secrets.GITLAB_TOKEN }}" ]; then
950+
echo "::error::GITLAB_TOKEN secret is not set"
951+
error_count=$((error_count + 1))
952+
fi
953+
954+
if [ -z "${{ secrets.GITLAB_TRIGGER_URL }}" ]; then
955+
echo "::error::GITLAB_TRIGGER_URL secret is not set"
956+
error_count=$((error_count + 1))
957+
fi
958+
959+
# Check required outputs from previous jobs
960+
if [ -z "${{ needs.build-artifact.outputs.NC_VERSION }}" ]; then
961+
echo "::error::NC_VERSION output from build-artifact job is not set"
962+
error_count=$((error_count + 1))
963+
else
964+
echo "✓ NC_VERSION: ${{ needs.build-artifact.outputs.NC_VERSION }}"
965+
fi
966+
967+
if [ -z "${{ needs.upload-to-artifactory.outputs.ARTIFACTORY_LAST_BUILD_PATH }}" ]; then
968+
echo "::error::ARTIFACTORY_LAST_BUILD_PATH output from upload-to-artifactory job is not set"
969+
error_count=$((error_count + 1))
970+
else
971+
echo "✓ ARTIFACTORY_LAST_BUILD_PATH: ${{ needs.upload-to-artifactory.outputs.ARTIFACTORY_LAST_BUILD_PATH }}"
972+
fi
973+
974+
# Check GitHub context variables
975+
if [ -z "${{ github.sha }}" ]; then
976+
echo "::error::github.sha is not set"
977+
error_count=$((error_count + 1))
978+
else
979+
echo "✓ GITHUB_SHA: ${{ github.sha }}"
980+
fi
981+
982+
if [ -z "${{ github.run_id }}" ]; then
983+
echo "::error::github.run_id is not set"
984+
error_count=$((error_count + 1))
985+
else
986+
echo "✓ BUILD_ID: ${{ github.run_id }}"
987+
fi
988+
989+
if [ -z "${{ github.ref_name }}" ]; then
990+
echo "::error::github.ref_name is not set"
991+
error_count=$((error_count + 1))
992+
else
993+
echo "✓ BRANCH: ${{ github.ref_name }}"
994+
fi
995+
996+
# Abort if any required variable is not set
997+
if [ $error_count -ne 0 ]; then
998+
echo "::error::Required variables are not set. Aborting."
999+
exit 1
1000+
fi
1001+
1002+
echo "✅ All required variables are set"
9421003
- name: Trigger remote workflow
9431004
run: |
9441005
# Enable command echo for debugging purposes

0 commit comments

Comments
 (0)