Skip to content
Snippets Groups Projects
Commit 6686d8e3 authored by jurgenhaas's avatar jurgenhaas
Browse files

gitlab-ci-cd/drupal#28 Make it work in pipelines too

parent b9792bc5
No related branches found
No related tags found
1 merge request!11Merging develop into main
......@@ -45,24 +45,30 @@ function parseUrl() {
}
SOURCEBRANCH=$(git rev-parse --abbrev-ref HEAD)
if [[ "$SOURCEBRANCH" == "main" ]]; then
echo "Main branch can not be merged."
exit 1
elif [[ "$SOURCEBRANCH" == "develop" ]]; then
TARGETBRANCH=main
else
TARGETBRANCH=develop
if [[ "x$TARGETBRANCH" == "x" ]]; then
if [[ "$SOURCEBRANCH" == "main" ]]; then
echo "Main branch can not be merged."
exit 1
elif [[ "$SOURCEBRANCH" == "develop" ]]; then
TARGETBRANCH=main
else
TARGETBRANCH=develop
fi
fi
if [[ "$TARGETBRANCH" == "$SOURCEBRANCH" ]]; then
echo "Source and target branches must be different."
exit 2
fi
if [[ -n ${CI_SERVER_HOST} ]]; then
GITLAB_URL=https://$CI_SERVER_HOST
fi
if [[ "x${GITLAB_URL}" == "x" ]]; then
echo "Missing GITLAB_URL environment variable, should be set to e.g. https://gitlab.lakedrops.com"
exit 2
exit 3
fi
if [[ "x${GITLAB_PRIVATE_TOKEN}" == "x" ]]; then
echo "Missing GITLAB_PRIVATE_TOKEN environment variable"
exit 3
exit 4
fi
parseUrl "$GITLAB_URL"
host1=$host
......@@ -70,7 +76,7 @@ parseUrl "$(git config remote.origin.url)"
host2=$host
if [[ "$host1" != "$host2" ]]; then
echo "This repository doesn't match the provided GitLab instance"
exit 4
exit 5
fi
if [[ -n ${CI_PROJECT_ID} ]]; then
......@@ -83,7 +89,7 @@ else
PRJID=$(echo "$result" | jq -r .[0]."id")
if [[ $(isNumeric "$PRJID") -eq 1 ]]; then
echo "Can not find project ID"
exit 5
exit 6
fi
fi
......@@ -93,7 +99,7 @@ gitlab 201 POST projects/"$PRJID"/merge_requests --data "source_branch=$SOURCEBR
MRID=$(echo "$result" | jq -r ."iid")
if [[ $(isNumeric "$MRID") -eq 1 ]]; then
echo "Can not create merge request"
exit 6
exit 7
fi
echo "Created MR at $(echo "$result" | jq -r ."web_url")"
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment