Skip to content

Instantly share code, notes, and snippets.

@khoipro
Created August 28, 2019 02:34
Show Gist options
  • Select an option

  • Save khoipro/c7dcb4155a3f00dfccd37548cf6a564e to your computer and use it in GitHub Desktop.

Select an option

Save khoipro/c7dcb4155a3f00dfccd37548cf6a564e to your computer and use it in GitHub Desktop.
#Devops - Check Git remote repository exists
// 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