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() { ...@@ -45,24 +45,30 @@ function parseUrl() {
} }
SOURCEBRANCH=$(git rev-parse --abbrev-ref HEAD) SOURCEBRANCH=$(git rev-parse --abbrev-ref HEAD)
if [[ "$SOURCEBRANCH" == "main" ]]; then if [[ "x$TARGETBRANCH" == "x" ]]; then
echo "Main branch can not be merged." if [[ "$SOURCEBRANCH" == "main" ]]; then
exit 1 echo "Main branch can not be merged."
elif [[ "$SOURCEBRANCH" == "develop" ]]; then exit 1
TARGETBRANCH=main elif [[ "$SOURCEBRANCH" == "develop" ]]; then
else TARGETBRANCH=main
TARGETBRANCH=develop else
TARGETBRANCH=develop
fi
fi
if [[ "$TARGETBRANCH" == "$SOURCEBRANCH" ]]; then
echo "Source and target branches must be different."
exit 2
fi fi
if [[ -n ${CI_SERVER_HOST} ]]; then if [[ -n ${CI_SERVER_HOST} ]]; then
GITLAB_URL=https://$CI_SERVER_HOST GITLAB_URL=https://$CI_SERVER_HOST
fi fi
if [[ "x${GITLAB_URL}" == "x" ]]; then if [[ "x${GITLAB_URL}" == "x" ]]; then
echo "Missing GITLAB_URL environment variable, should be set to e.g. https://gitlab.lakedrops.com" echo "Missing GITLAB_URL environment variable, should be set to e.g. https://gitlab.lakedrops.com"
exit 2 exit 3
fi fi
if [[ "x${GITLAB_PRIVATE_TOKEN}" == "x" ]]; then if [[ "x${GITLAB_PRIVATE_TOKEN}" == "x" ]]; then
echo "Missing GITLAB_PRIVATE_TOKEN environment variable" echo "Missing GITLAB_PRIVATE_TOKEN environment variable"
exit 3 exit 4
fi fi
parseUrl "$GITLAB_URL" parseUrl "$GITLAB_URL"
host1=$host host1=$host
...@@ -70,7 +76,7 @@ parseUrl "$(git config remote.origin.url)" ...@@ -70,7 +76,7 @@ parseUrl "$(git config remote.origin.url)"
host2=$host host2=$host
if [[ "$host1" != "$host2" ]]; then if [[ "$host1" != "$host2" ]]; then
echo "This repository doesn't match the provided GitLab instance" echo "This repository doesn't match the provided GitLab instance"
exit 4 exit 5
fi fi
if [[ -n ${CI_PROJECT_ID} ]]; then if [[ -n ${CI_PROJECT_ID} ]]; then
...@@ -83,7 +89,7 @@ else ...@@ -83,7 +89,7 @@ else
PRJID=$(echo "$result" | jq -r .[0]."id") PRJID=$(echo "$result" | jq -r .[0]."id")
if [[ $(isNumeric "$PRJID") -eq 1 ]]; then if [[ $(isNumeric "$PRJID") -eq 1 ]]; then
echo "Can not find project ID" echo "Can not find project ID"
exit 5 exit 6
fi fi
fi fi
...@@ -93,7 +99,7 @@ gitlab 201 POST projects/"$PRJID"/merge_requests --data "source_branch=$SOURCEBR ...@@ -93,7 +99,7 @@ gitlab 201 POST projects/"$PRJID"/merge_requests --data "source_branch=$SOURCEBR
MRID=$(echo "$result" | jq -r ."iid") MRID=$(echo "$result" | jq -r ."iid")
if [[ $(isNumeric "$MRID") -eq 1 ]]; then if [[ $(isNumeric "$MRID") -eq 1 ]]; then
echo "Can not create merge request" echo "Can not create merge request"
exit 6 exit 7
fi fi
echo "Created MR at $(echo "$result" | jq -r ."web_url")" 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