Skip to content

Instantly share code, notes, and snippets.

@rakesh1988
Created July 3, 2024 13:25
Show Gist options
  • Save rakesh1988/fa77b0fe29615e70baaa7716c09dd301 to your computer and use it in GitHub Desktop.
Save rakesh1988/fa77b0fe29615e70baaa7716c09dd301 to your computer and use it in GitHub Desktop.
#!/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