Created
December 6, 2016 16:11
-
-
Save melo/cf01fd687f096163e5e781b3bb75b1f8 to your computer and use it in GitHub Desktop.
Trigger a Gitlab CI build with 'git build'
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/sh | |
project_id=`git config gitlab.project-id` | |
if [ -z "$project_id" ] ; then | |
echo "FATAL: could not find gitlab.project-id on your config" | |
echo "To fix: use 'git config gitlab.project-id ID'" | |
echo " find the project ID in the Settings > Triggers page," | |
echo " in the examples, it is the number in the URL" | |
exit 1 | |
fi | |
token=`git config gitlab.trigger-token` | |
if [ -z "$token" ] ; then | |
echo "FATAL: could not find gitlab.trigger-token on your config" | |
echo "To fix: use 'git config gitlab.trigger-token TOKEN'" | |
echo " you can create a TOKEN on your project page, Settings > Triggers" | |
exit 1 | |
fi | |
branch="${1:-`git name-rev --name-only HEAD`}" | |
if [ -z "$branch" ] ; then | |
echo "FATAL: could not determine branch to build" | |
echo "To fix: use 'git build BRANCH', or try to understand why" | |
echo " 'git name-rev --name-only HEAD' returns nothing..." | |
exit 1 | |
fi | |
echo "Triggering build for branch '$branch'" | |
curl -X POST \ | |
-F "token=$token" \ | |
-F "ref=$branch" \ | |
-F "variables[BUILD_VIA]=git-build" \ | |
"https://gitlab.com/api/v3/projects/$project_id/trigger/builds" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment