jenkins将.netframework发布项目到IIS
一、Jenkins所在服务器上安装VS2019,免得各种环境不对。二、下载jenkins:https://www.jenkins.io/Jenkins 2.249.2 LTS.msi三、安装jdk-8环境四、安装Jenkins创建用户:admin 密码:test@123安装插件:GitLabGitlab Hook五、安装IIS并安装Web Deploy 3.6,如果已安装,先卸载掉,再重新安装安装
Jenkins 环境搭建:
一、Jenkins所在服务器上安装VS2019,免得各种环境不对
配置环境变量Path:
C:\Program Files (x86)\Microsoft Visual Studio\2019\Professional\MSBuild\Current\Bin
二、下载jenkins:https://www.jenkins.io/
Jenkins 2.249.2 LTS.msi
三、安装jdk-8环境
四、安装:Nuget
下载nuget.exe:Installing NuGet client tools | Microsoft Docs
放到目录:C:\Windows\System32,这样就不需要添加Path系统环境变量了
四、安装Jenkins+Git
创建用户:admin 密码:test@123
安装插件:
Git plugin
GitLab Plugin
Gitlab Hook Plugin
MSBuild
配置gitlab ssh 免密拉取代码
#要安装:Git-2.11.0-64-bit.exe 能运行git ssh key
#配置git ssh key 将生成的公钥添加到GitLab:
ssh-keygen -t rsa -b 2048 -C "admin@example.com"
#将私钥id_rsa配置到jenkins里
私钥id_rsa配置到jenkins里
公钥配置到Gitlab
Jenkins配置
特别注意:我下面使用的“iisweb”命名,如果添加新的项目,命名请全局替换,不要造成不必要的各种问题。包括脚本中的和发布文件及iis站点名称
代理签出到:C:\jenkins\iis.web 防止Jenkins 工作目录包含空格影响构建
构建脚本:
nuget restore C:\jenkins\iis.web\IIS.Web.sln
C:\jenkins\iis.web\IIS.Web\IIS.Web.csproj
/p:Configuration=Release /p:DeployOnBuild=true /p:PublishProfile="C:\Jenkins\pubxml\iisweb.pubxml" /p:VisualStudioVersion=16.0 /p:AllowUntrustedCertificate=true /p:solutionDir=C:\jenkins\iis.web /m:4 /nr:False /p:DeployIisAppPath=iisweb /p:SkipExtraFilesOnServer=True /p:AfterAddIisSettingAndFileContentsToSourceManifest=Add
iisweb.pubxml (注意,里面有排除掉配置文件Web.config不发布到服务器)
<?xml version="1.0" encoding="utf-8"?>
<!--
This file is used by the publish/package process of your Web project. You can customize the behavior of this process
by editing this MSBuild file. In order to learn more about this please visit http://go.microsoft.com/fwlink/?LinkID=208121.
-->
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<WebPublishMethod>MSDeploy</WebPublishMethod>
<LastUsedBuildConfiguration>Release</LastUsedBuildConfiguration>
<LastUsedPlatform>Any CPU</LastUsedPlatform>
<SiteUrlToLaunchAfterPublish />
<ExcludeApp_Data>False</ExcludeApp_Data>
<MSDeployServiceURL>http://192.168.1.200</MSDeployServiceURL>
<DeployIisAppPath>IIS.Web</DeployIisAppPath>
<RemoteSitePhysicalPath />
<!-- True:不删除未包含文件,False:删除无关文件 -->
<SkipExtraFilesOnServer>True</SkipExtraFilesOnServer>
<MSDeployPublishMethod>RemoteAgent</MSDeployPublishMethod>
<EnableMSDeployBackup>False</EnableMSDeployBackup>
<IncludeSetACLProviderOnDestination>False</IncludeSetACLProviderOnDestination>
<UserName>administrator</UserName>
<Password>abc123@</Password>
<PublishDatabaseSettings>
<Objects xmlns="" />
</PublishDatabaseSettings>
<ExcludeGeneratedDebugSymbol>False</ExcludeGeneratedDebugSymbol>
<!-- 应用自定义过滤规则 AddCustomSkipRules -->
<AfterAddIisSettingAndFileContentsToSourceManifest>Add</AfterAddIisSettingAndFileContentsToSourceManifest>
</PropertyGroup>
<Target Name="Add">
<Message Text="Adding Custom Skip Rules" />
<ItemGroup>
<MsDeploySkipRules Include="SkipWebConfig">
<SkipAction></SkipAction>
<ObjectName>filePath</ObjectName>
<AbsolutePath>Web.config</AbsolutePath>
<Apply>Source</Apply>
<XPath></XPath>
</MsDeploySkipRules>
<MsDeploySkipRules Include="SkipWebConfig">
<SkipAction></SkipAction>
<ObjectName>filePath</ObjectName>
<AbsolutePath>Web.config</AbsolutePath>
<Apply>Destination</Apply>
<XPath></XPath>
</MsDeploySkipRules>
<MsDeploySkipRules Include="Skipnlog">
<SkipAction></SkipAction>
<ObjectName>filePath</ObjectName>
<AbsolutePath>nlog.config</AbsolutePath>
<Apply>Source</Apply>
<XPath></XPath>
</MsDeploySkipRules>
<MsDeploySkipRules Include="Skipnlog">
<SkipAction></SkipAction>
<ObjectName>filePath</ObjectName>
<AbsolutePath>nlog.config</AbsolutePath>
<Apply>Destination</Apply>
<XPath></XPath>
</MsDeploySkipRules>
</ItemGroup>
</Target>
</Project>
IIS站点
配置代码提交自动构建:
admin_api_token 通过这里创建:
Jenkins 关掉跨域规则和允许匿名访问,否则Gitlab webhook 会失败
允许匿名访问
关掉跨域规则
打开jenkins 安装目录:C:\Program Files\Jenkins\jenkins.xml
这是添加的: -Dhudson.security.csrf.GlobalCrumbIssuerConfiguration.DISABLE_CSRF_PROTECTION=true
<arguments>-Xrs -Xmx256m -Dhudson.lifecycle=hudson.lifecycle.WindowsServiceLifecycle -Dhudson.security.csrf.GlobalCrumbIssuerConfiguration.DISABLE_CSRF_PROTECTION=true -jar "C:\Program Files\Jenkins\jenkins.war" --httpPort=8080 --webroot="%LocalAppData%\Jenkins\war"</arguments>
完整配置文件:
<!--
The MIT License
Copyright (c) 2004-2017, Sun Microsystems, Inc., Kohsuke Kawaguchi, Oleg Nenashev, and other Jenkins contributors
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
-->
<!--
Windows service definition for Jenkins.
To uninstall, run "jenkins.exe stop" to stop the service, then "jenkins.exe uninstall" to uninstall the service.
Both commands don't produce any output if the execution is successful.
-->
<service>
<id>jenkins</id>
<name>Jenkins</name>
<description>This service runs Jenkins automation server.</description>
<env name="JENKINS_HOME" value="%LocalAppData%\Jenkins\.jenkins"/>
<!--
if you'd like to run Jenkins with a specific version of Java, specify a full path to java.exe.
The following value assumes that you have java in your PATH.
-->
<executable>C:\Program Files\Java\jdk1.8.0_201\bin\java.exe</executable>
<arguments>-Xrs -Xmx256m -Dhudson.lifecycle=hudson.lifecycle.WindowsServiceLifecycle -Dhudson.security.csrf.GlobalCrumbIssuerConfiguration.DISABLE_CSRF_PROTECTION=true -jar "C:\Program Files\Jenkins\jenkins.war" --httpPort=8080 --webroot="%LocalAppData%\Jenkins\war"</arguments>
<!--
interactive flag causes the empty black Java window to be displayed.
I'm still debugging this.
<interactive />
-->
<logmode>rotate</logmode>
<onfailure action="restart"/>
<!--
In the case WinSW gets terminated and leaks the process, we want to abort
these runaway JAR processes on startup to prevent corruption of JENKINS_HOME.
So this extension is enabled by default.
-->
<extensions>
<!-- This is a sample configuration for the RunawayProcessKiller extension. -->
<extension enabled="true" className="winsw.Plugins.RunawayProcessKiller.RunawayProcessKillerExtension" id="killOnStartup">
<pidfile>%LocalAppData%\Jenkins\jenkins.pid</pidfile>
<stopTimeout>10000</stopTimeout>
<stopParentFirst>false</stopParentFirst>
</extension>
</extensions>
<!-- See the referenced examples for more options -->
</service>
重启jenkins ,最终效果
Gitlab 配置Webhook
Web服务器:
五、安装IIS并安装Web Deploy 3.6
a.安装IIS时注意:管理服务一定要勾选
b.安装Web Deploy 3.6,如果已安装,先卸载掉,再重新安装
Web Deploy 3.6 : The Official Microsoft IIS Site
特别注意:安装Web Deploy 选【自定义安装】=>Complete【整个功能将被安装在本地硬盘上】
如果不是选择:【整个功能将被安装在本地硬盘上】 那你将看不到IIS 右键选项里的部属
防火墙放开端口:8172和80
六、VS2019发布
运行效果:
更多推荐
所有评论(0)