Docker-Jenkins-Deployment Dear 丶 2024-03-27 10:11 55阅读 0赞 Docker-Jenkins-Deployment /* MAINTAINER WinJayX <WinJayX@Gmail.com> * LABEL description="This is DotNetCore5 Project" * LABEL version="1.0" * 1.Git地址 * 2.分支信息 * 3.解决方案 * 4.执行文件 * 5.镜像地址*2 * 6.Dokcer名称 * 7.Docker端口 */ //变量 Branch、ImageTag 在参数化构建中添加 /* MAINTAINER WinJayX <WinJayX@Gmail.com> * LABEL description="This is FZ_CaseCenter_Web Project" */ stage('Git Checkout') { node('MSBuild') { checkout([$class: 'GitSCM', branches: [[name: '${Branch}']], doGenerateSubmoduleConfigurations: false, extensions: [], submoduleCfg: [], userRemoteConfigs: [[credentialsId: '973c9a08-4d62-4f8a-8792-7a214b7ffe66', url: 'https://git.nercoa.com/moe/NationalCompetition.git']]]) } } stage('Build'){ node('MSBuild') { echo '编译解决方案' bat "$DOTNET publish -c Release -o \"${WORKSPACE}/publish\" \"src/NVIC.Web/NVIC.Web.csproj\" " } } stage('Backup To The Site Directory'){ node('MSBuild') { dir('publish') { bat "zip -r ${BUILD_NUMBER}.zip ./" } echo '拷贝文件至备份目录' bat "xcopy \"publish/${BUILD_NUMBER}.zip\" \"${BACKUP_SHARE_DIR}/${JOB_NAME}/\" /fyi " bat "rm -rf publish*" } } stage('Download Project Code'){ node('Container') { echo '建立业务目录' //sh "mkdir -p ${JOB_NAME} && cd ${JOB_NAME}" echo '下载程序' sh "curl -O ${PUBLISH_HOST}/${JOB_NAME}/${BUILD_NUMBER}.zip" echo '解压源程序' sh "unzip -o ${BUILD_NUMBER}.zip && rm -f ${BUILD_NUMBER}.zip" } } stage('Build And Push Image') { node('Container') { sh ''' REPOSITORY=hub.nercoa.com/unify_nvic/web:${ImageTag} cat > Dockerfile << EOF FROM mcr.microsoft.com/dotnet/aspnet:5.0.0 MAINTAINER WinJayX <WinJayX@Gmail.com> LABEL description="This is FZ_CaseCenter_Web Project" LABEL version="5.0.7" USER root RUN echo 'deb https://mirrors.tuna.tsinghua.edu.cn/debian/ buster main contrib non-free\\r\\ndeb https://mirrors.tuna.tsinghua.edu.cn/debian/ buster-updates main contrib non-free\\r\\ndeb https://mirrors.tuna.tsinghua.edu.cn/debian/ buster-backports main contrib non-free\\r\\ndeb https://mirrors.tuna.tsinghua.edu.cn/debian-security buster/updates main contrib non-free\\r\\n' > /etc/apt/sources.list RUN cat /etc/apt/sources.list ### 安装显示验证码图片 RUN apt-get update -y && apt-get upgrade -y RUN apt-get install libgdiplus -y && mkdir -p /app && ln -s /usr/lib/libgdiplus.so /app/gdiplus.dll ##ln -s libgdiplus.so gdiplus.dll RUN ln -s /lib/x86_64-linux-gnu/libdl-2.*.so /lib/x86_64-linux-gnu/libdl.so ### 对连接sqlServer协议进行降级 RUN sed -i 's/TLSv1.2/TLSv1/g' /etc/ssl/openssl.cnf &&\ sed -i 's/SECLEVEL=2/SECLEVEL=1/g' /etc/ssl/openssl.cnf WORKDIR /app COPY . /app/ ENTRYPOINT ["dotnet", "NVIC.Web.dll"] EOF docker build -t $REPOSITORY . docker login hub.nercoa.com -u admin -p Nerc.nerc/1 docker push $REPOSITORY ''' } } stage('Deploy To The Test Server') { node('Docker') { sh ''' REPOSITORY=hub.nercoa.com/unify_nvic/web:${ImageTag} docker rm -f Unify_NVIC_Web || true docker container run -d \ --volume /etc/localtime:/etc/localtime:ro \ --add-host mssql1.dev.db:202.205.161.100 \ --add-host mssql2.dev.db:202.205.161.101 \ --add-host mssql3.dev.db:202.205.161.112 \ --restart always \ --user root \ --name Unify_NVIC_Web \ --hostname Unify_NVIC_Web \ -p 8002:80 $REPOSITORY ''' } } /* stage('Deploying To The Production Server'){ timeout(time: 1, unit: 'DAYS') { input message: 'Deploying To The Production Server?', ok: 'Deployment' } } stage('Deploy To The Production Docker Server') { node('App06') { sh ''' cd /mnt/Docker/019.CC_Web REPOSITORY=hub.nercoa.com/unify_nvic/admin:${ImageTag} docker rm -f FZ_CaseCenter_Web || true docker container run -d \ --volume /etc/localtime:/etc/localtime:ro \ --volume `pwd`/Config:/app/Config \ --restart always \ --user root \ --name FZ_CaseCenter_Web \ -h FZ_CaseCenter_Web \ -p 8015:80 \ $REPOSITORY ''' } } */
还没有评论,来说两句吧...