Created
August 28, 2019 02:34
-
-
Save khoipro/c7dcb4155a3f00dfccd37548cf6a564e to your computer and use it in GitHub Desktop.
#Devops - Check Git remote repository exists
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
| // Inside repositories loop | |
| echo -e "[$SITE_NAME] Git URL: ${GIT_URL}" | |
| // What is this? | |
| // It check if repository exists or not and set remote url correctly. | |
| // If not, sometime it will exit code 1 while running GitLab CI. | |
| # Add git repo | |
| git remote | grep "${SITE_NAME}" &> /dev/null | |
| if [ $? == 0 ]; then | |
| echo -e "Repository exists. Set URL for repository." | |
| git remote set-url ${SITE_NAME} ${GIT_URL} | |
| else | |
| echo -e "Repository doesn't exist. We must add URL for repository." | |
| git remote add ${SITE_NAME} ${GIT_URL} | |
| fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment