如果你对该文章中的内容有疑问/不解,可以点击此处链接提问
要注明问题和此文章链接地址 点击此处跳转
<code class="language-php">#!/bin/bash
REPO_URL="https://codeup.aliyun.com/66b1e3e339eec40a6d4bf3fe/test_yx.git"
REPO_DIR="/www/wwwroot/test-yx.test.90ckm.com"
NETRC_FILE=~/.netrc
if [ ! -f "$NETRC_FILE" ]; then
cat <<EOL > ~/.netrc
machine codeup.aliyun.com
login git账号例如34689347
password git密码
EOL
chmod 600 ~/.netrc
fi
git config --global user.name "34689347"
git config --global user.email "34689347@qq.com"
if [ ! -d "$REPO_DIR" ]; then
git clone $REPO_URL $REPO_DIR
if [ $? -ne 0 ]; then
echo "克隆失败"
exit 1
fi
fi
cd $REPO_DIR
git fetch ${REPO_URL}
DEFAULT_BRANCH=$(git remote show ${REPO_URL} | grep 'HEAD branch' | cut -d' ' -f5)
git checkout $DEFAULT_BRANCH
git pull ${REPO_URL} $DEFAULT_BRANCH
if [ ! -z "${CI_COMMIT_ID}" ]; then
echo "检出: ${CI_COMMIT_ID}"
FULL_COMMIT_ID=$(git rev-parse --verify ${CI_COMMIT_ID} 2>/dev/null)
if [ $? -eq 0 ]; then
git checkout ${FULL_COMMIT_ID}
else
echo "找不到"
git log --oneline -n 10
exit 1
fi
fi
</code>