Jenkins中使用Git时遇到的两个坑

1、jenkins-slave 机器上git报错. Host key verification failed.

git pull

18:37:24 Host key verification failed.
18:37:24 fatal: Could not read from remote repository.
18:37:24 
18:37:24 Please make sure you have the correct access rights

18:37:24 and the repository exists.

clone 也是一样,都不好使。

具体现象是
1-如果在cmd中执行,git正常使用, .ssh 能正确起效.  
2-如果在Jenkins中执行, git就报上述错误. 

排查得知, jnlp 程序有一个Install as windows service 菜单项,手贱点了下。
然后某个晚上断电了,电脑起来后就以Service的途径在运行jenkins-slave. 
目前尚不确定服务为什么找不到.ssh里的数据,但有一个简单的办法实现自动执行jnlp小程序:
[windows+R run] "shell:Startup", 打开 ['启动'文件夹], 将jnlp小程序扔里面.


2、jenkins 中 git commit 失败.

git commit [*******] -m [******]
18:49:32 
18:49:32 *** Please tell me who you are.
18:49:32 
18:49:32 Run
18:49:32 
18:49:32   git config --global user.email "you@example.com"
18:49:32   git config --global user.name "Your Name"
18:49:32 
18:49:32 to set your account's default identity.
18:49:32 Omit --global to set the identity only in this repository.
18:49:32 
18:49:32 fatal: unable to auto-detect email address (got 'Jenkins@********.(none)')

具体现象是
1-如果在cmd中执行git commit , 没毛病,  使用 git config -l 查看,也都是有的.
2-在jenkins中就报上述错误.

排查后得知

如果在jenkins 中运行git config -l, 确实没有设置 user.email / user.name
如果用where git , 可以看到在cmd中,路径为
C:\Program Files\Git\cmd\git.exe
C:\Program Files\Git\bin\git.exe
而在bash,或jenkins中,则为
C:\Program Files\Git\mingw64\bin\git.exe  <-----------
C:\Program Files\Git\cmd\git.exe
C:\Program Files\Git\bin\git.exe

解决方法是在jenkins中执行git config user.email ,  git config user.name.


PS: 我推测上述问题都可以基于 jenkins中运行的是 mingw64\bin\git.exe 来设计其他解决方法。
比如问题1:拷贝 .ssh 到 某个目录下,不过 mingw64\ | C:\Program Files\Git\  | C:\Program Files\Git\usr 我都试了,没好使:(
问题2:不使用global config, 而是使用local的.

  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
1. 安装.NET Core SDK 在Jenkins使用.NET Core编译项目之前,需要先安装.NET Core SDK。可以在官方网站下载适合您的操作系统的SDK。 2. 安装Jenkins插件 使用Jenkins进行.NET Core编译需要安装MSBuild插件。可以在Jenkins插件管理器搜索并安装该插件。 3. 配置工具路径 在Jenkins配置.NET Core SDK的路径非常重要。在Jenkins管理界面,选择“系统设置”,找到“.NET Core SDK”并配置SDK的路径。确保SDK路径指向正确的目录。 4. 配置构建步骤 在Jenkins配置构建步骤,需要使用“MSBuild”构建步骤。将项目的.csproj文件作为参数传递给MSBuild构建步骤,如下所示: ``` msbuild.exe /t:restore msbuild.exe /t:build /p:Configuration=Release /p:OutputPath=<path to publish output> /p:PublishProfile=<path to publish profile> <path to project file> ``` 其,“/t:restore”用于还原项目依赖项,“/t:build”用于编译项目,“/p:Configuration=Release”指定编译配置为Release,“/p:OutputPath=<path to publish output>”指定发布输出路径,“/p:PublishProfile=<path to publish profile>”指定发布配置文件路径,“<path to project file>”指定项目文件路径。 5. 配置发布 在Jenkins配置自动发布非常简单。只需使用“Publish over SSH”插件将构建输出文件上传到目标服务器即可。 6. 配置IIS 在将应用程序部署到IIS,需要做一些额外的配置。确保在IIS创建应用程序池,并将.NET Core的版本设置为与安装的SDK版本相同。还需要安装.NET Core Hosting Bundle,以便IIS能够正确地运行.NET Core应用程序。 总结 .NET Core是一个非常好的开发框架,但在使用Jenkins进行部署,需要注意一些细节。通过正确地安装和配置.NET Core SDK、Jenkins插件和IIS,可以轻松地使用Jenkins部署.NET Core应用程序。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值