Last active
March 23, 2022 02:21
-
-
Save sosiristseng/bd4cba7239e1b4ca8edbb1848d11158d to your computer and use it in GitHub Desktop.
Git Operations in GitLab
This file contains 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
script: | |
- bash update.sh | |
- | | |
if [[ -n $(git status --porcelain) ]]; then | |
echo "Commiting updates" | |
git config --global user.name "${GITLAB_USER_NAME}" | |
git config --global user.email "${GITLAB_USER_EMAIL}" | |
git add . | |
git commit -m "Automated update: $(date '+%Y-%m-%d-%H-%M-%S')" | |
git push "https://${GITLAB_USER_NAME}:${GIT_PUSH_TOKEN}@${CI_REPOSITORY_URL#*@}" | |
exit; | |
else | |
echo "no change, nothing to commit" | |
fi |
This file contains 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
script: | |
- bash update.sh | |
- | | |
if [[ -n $(git status --porcelain) ]]; then | |
echo "Commiting updates" | |
NEW_BR=auto-update-$(date '+%Y-%m-%d-%H-%M-%S') | |
git config --global user.name "${GITLAB_USER_NAME}" | |
git config --global user.email "${GITLAB_USER_EMAIL}" | |
git checkout -b ${NEW_BR} | |
git add . | |
git commit -m "${NEW_BR}" | |
git push "https://${GITLAB_USER_NAME}:${GIT_PUSH_TOKEN}@${CI_REPOSITORY_URL#*@}" \ | |
-o merge_request.create \ | |
-o merge_request.target="${CI_DEFAULT_BRANCH}" \ | |
-o merge_request.merge_when_pipeline_succeeds \ | |
-o merge_request.remove_source_branch \ | |
-o merge_request.title="${NEW_BR}" \ | |
-o merge_request.label="automated update" \ | |
-o merge_request.assign="${GITLAB_USER_NAME}" | |
exit; | |
else | |
echo "no change, nothing to commit" | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment