Created
July 3, 2024 13:25
-
-
Save rakesh1988/fa77b0fe29615e70baaa7716c09dd301 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# Check if BRANCH_NAME is provided | |
if [ -z "$1" ]; then | |
echo "Error: BRANCH_NAME is required." | |
exit 1 | |
fi | |
# Variables | |
SYNC_DIRECTION="upload" | |
BRANCH_NAME=$1 | |
# GitLab project URL (replace with your actual URL) | |
GITLAB_PROJECT_URL="https://gitlab.example.com/api/v4/projects/your_project_id/trigger/pipeline" | |
# Your GitLab personal access token | |
ACCESS_TOKEN="your_personal_access_token" | |
# Trigger token (created in GitLab CI/CD settings) | |
TRIGGER_TOKEN="your_trigger_token" | |
# Trigger the pipeline | |
response=$(curl --request POST "$GITLAB_PROJECT_URL" \ | |
--form "token=$TRIGGER_TOKEN" \ | |
--form "ref=sync" \ | |
--form "variables[BRANCH_NAME]=$BRANCH_NAME" \ | |
--form "variables[SYNC_DIRECTION]=$SYNC_DIRECTION" \ | |
--header "PRIVATE-TOKEN: $ACCESS_TOKEN") | |
# Print response | |
echo "Response from GitLab:" | |
echo "$response" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment