Skip to content

Commit 1e9a366

Browse files
committed
Update gitlab_webhook_build.yml
1 parent 7e62a5c commit 1e9a366

File tree

1 file changed

+22
-7
lines changed

1 file changed

+22
-7
lines changed

.github/workflows/gitlab_webhook_build.yml

Lines changed: 22 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -48,14 +48,29 @@ jobs:
4848
4949
# Extract information from webhook payload
5050
if [ "${{ github.event_name }}" = "repository_dispatch" ]; then
51-
# Get branch from payload (GitLab sends 'ref' like 'refs/heads/enterprise')
52-
GITLAB_REF="${{ github.event.client_payload.ref || 'refs/heads/enterprise' }}"
53-
GITLAB_BRANCH=$(echo "$GITLAB_REF" | sed 's|refs/heads/||')
51+
# Check if GitLab template variables were replaced properly
52+
RAW_REF="${{ github.event.client_payload.ref }}"
53+
RAW_USER="${{ github.event.client_payload.user_name }}"
5454
55-
# Get commit info
56-
GITLAB_COMMIT="${{ github.event.client_payload.after || github.event.client_payload.checkout_sha || '' }}"
57-
GITLAB_COMMIT_MSG="${{ github.event.client_payload.commits[0].message || 'Webhook trigger' }}"
58-
GITLAB_USER="${{ github.event.client_payload.user_name || github.event.client_payload.user_username || 'unknown' }}"
55+
echo "Raw ref from payload: '$RAW_REF'"
56+
echo "Raw user from payload: '$RAW_USER'"
57+
58+
# If template variables weren't replaced (still contain %), use defaults
59+
if [[ "$RAW_REF" == *"%{"* ]] || [ -z "$RAW_REF" ]; then
60+
echo "⚠️ GitLab template variables not replaced, using defaults"
61+
GITLAB_REF="refs/heads/enterprise"
62+
GITLAB_BRANCH="enterprise"
63+
GITLAB_USER="GitLab User"
64+
GITLAB_COMMIT=""
65+
GITLAB_COMMIT_MSG="GitLab webhook trigger (template variables not replaced)"
66+
else
67+
echo "✅ GitLab template variables replaced successfully"
68+
GITLAB_REF="${{ github.event.client_payload.ref }}"
69+
GITLAB_BRANCH=$(echo "$GITLAB_REF" | sed 's|refs/heads/||')
70+
GITLAB_USER="${{ github.event.client_payload.user_name }}"
71+
GITLAB_COMMIT="${{ github.event.client_payload.after }}"
72+
GITLAB_COMMIT_MSG="Push to $GITLAB_BRANCH by $GITLAB_USER"
73+
fi
5974
6075
echo "branch=$GITLAB_BRANCH" >> $GITHUB_OUTPUT
6176
echo "commit=$GITLAB_COMMIT" >> $GITHUB_OUTPUT

0 commit comments

Comments
 (0)