1、源代码编译后输出,针对NET5.0\6.0,7.0应该可以跟JAVA一样了
Jenkins配置netcore发布到Liunx下
1、构建部分:
execute Windows batch command
命令:
@echo off
echo 编译代码...
cd "%WORKSPACE%"
if exist %JOB_NAME%.zip del /s/q %JOB_NAME%.zip
if not exist D:\PM\temp\test\%JOB_NAME% md D:\PM\temp\test\%JOB_NAME%
echo "D:\PM\temp\%JOB_NAME%\%BUILD_ID%"
dotnet restore
dotnet build
IF %ERRORLEVEL% NEQ 0 GOTO ERROR
dotnet publish -o D:\PM\temp\test\%JOB_NAME%
IF %ERRORLEVEL% NEQ 0 GOTO ERROR
copy %WORKSPACE%\Dockerfile D:\PM\temp\test\%JOB_NAME%\
cd D:\PM\temp\test\%JOB_NAME%
D:\"Program Files"\WinRAR\WinRAR.exe a -k -r -s -m1 %JOB_NAME%.zip
copy D:\PM\temp\test\%JOB_NAME%\%JOB_NAME%.zip %WORKSPACE%\%JOB_NAME%.zip
cd D:\PM\temp\test
rmdir /s/q %JOB_NAME%
:ERROR
ECHO command failed
GOTO END
:END
IF %ERRORLEVEL% GEQ 0 EXIT /B %ERRORLEVEL%
EXIT /B 0
构建后操作:
1、Send build artifacts over SSH
Transfers:
1、Source Files \*.zip
2、Remove perfix \
3、Remote directory build/
4、Exec command
cd /usr/pm/build/ #进入到jenkins的打包目录
if [ -d ${JOB_NAME} ];then
echo "文件夹存在"
else
echo "文件夹不存在"
mkdir ${JOB_NAME}
fi
cp ${JOB_NAME}.zip ${JOB_NAME}
rm -d ${JOB_NAME}.zip
cd /usr/pm/build/${JOB_NAME}
if [ -f /usr/pm/build/${JOB_NAME}/${JOB_NAME}.zip ];then
echo "文件存在"
unzip ${JOB_NAME}.zip
rm -d ${JOB_NAME}.zip
fi
echo "复制dockerfile文件,注意名称要使用小写"
cd /usr/pm/build/${JOB_NAME} #进入到jenkins的打包目录
docker rm -f ${JOB_NAME}3031
docker build -t ${JOB_NAME} .
docker run --name=${JOB_NAME}3031 --restart=always --net=umsnet -p 3031:5000 -d -v /etc/ssl/openssl.cnf:/etc/ssl/openssl.cnf -v /usr/share/zoneinfo/Asia/Shanghai:/etc/localtime ${JOB_NAME}
rm -rf /usr/pm/build/${JOB_NAME}