内容目录
git打包shell
linux试试远程windows参考 https://www.ku0.cc/1147
# windows打包部分
ssh Server@192.168.0.2 "cmd /c if exist D:\\battlebuilds\\server_${Project}_${Branch} rmdir /s /q D:\\battlebuilds\\server_${Project}_${Branch}"
ssh Server@192.168.0.2 "cmd /c if not exist D:\\battlebuilds\server_${Project}_${Branch} mkdir D:\\battlebuilds\server_${Project}_${Branch}"
ssh Server@192.168.0.2 "cmd /c git clone http://${GIT_USERNAME}:${GIT_PASSWORD}@192.168.0.1/binan/server.git D:\\battlebuilds\\server_${Project}_${Branch} --branch ${Branch} --single-branch > D:\\battlebuilds\\checkout.log 2>&1"
ssh Server@192.168.0.2 "cmd /c \"cd /d D:\\battlebuilds\\server_${Project}_${Branch}\\server_tool\\Battle\\BattleWrapper && dotnet publish BattleWrapper.csproj -c Release -r win-x64 -p:PublishAot=true -o publish-dll --verbosity minimal\""
ssh Server@192.168.0.2 "cmd /c \"\
copy /Y D:\\battlebuilds\\server_${Project}_${Branch}\\server_tool\\Battle\\BattleWrapper\\publish-dll\\BattleWrapper.dll D:\\battlebuilds\\server_${Project}_${Branch}\\libs\\ && \
cd /d D:\\battlebuilds\\server_${Project}_${Branch}\\ && \
git add libs\\BattleWrapper.dll && \
git -c user.name=root -c user.email=admin@example.com commit -m \"Jenkins Build #${BUILD_NO} : 更新 BattleWrapper.dll\" && \
git push origin HEAD:${Branch}\""
报错1 目录无权限
提示fatal: could not create work tree dir 'D:\battlebuilds\server_1_master': Permission denied
解决
每次构建删除重建
ssh Server@192.168.0.2 "cmd /c if exist D:\\battlebuilds\\server_${Project}_${Branch} rmdir /s /q D:\\battlebuilds\\server_${Project}_${Branch}"
ssh Server@192.168.0.2 "cmd /c if not exist D:\\battlebuilds\server_${Project}_${Branch} mkdir D:\\battlebuilds\server_${Project}_${Branch}"
报错2 无git凭证
fatal: Unable to persist credentials with the 'wincredman' credential store. See https://aka.ms/gcm/credstores for more information. bash: line 1: /dev/tty: No such device or address error: failed to execute prompt script (exit code 1) fatal: could not read Username for 'http://192.168.0.1': No such file or directory
原因
linux git凭证无法传输到远程windows
解决
jenkins使用插件 https://plugins.jenkins.io/credentials-binding/
然后命令行使用变量${GIT_USERNAME} ${GIT_PASSWORD}
ssh Server@192.168.0.2 "cmd /c git clone http://${GIT_USERNAME}:${GIT_PASSWORD}@192.168.0.1/binan/server.git D:\\battlebuilds\\server_${Project}_${Branch} --branch ${Branch} --single-branch > D:\\battlebuilds\\checkout.log 2>&1"
报错3 无匹配分支
git push origin master error: src refspec master does not match any error: failed to push some refs to
原因
没有切换到master分支提交
解决
不切换分支并直接推送当前的 HEAD 到远程的 master 分支
git push origin HEAD:master