Jenkins Git fetch 引用旧提交

问题描述 投票:0回答:4

我正在为 Angular 6 应用程序创建 Jenkins CI 流程。 我创建了一个多配置项目。并在配置中选择以下值:

源代码管理:
Git:Repo_URL
要构建的分支:*/master
存储库浏览器:自动

构建触发器:
Gerrit 事件:已检查

Gerrit 触发器:
选择服务器:gerrit.*.com
触发:已创建补丁集
添加的命令包含正则表达式:[Rr][Ee][Vv][Ee][Rr][Ii][Ff][Yy]

动态触发配置:
格里特项目:
类型: Plair 图案: projName
分行:
类型:格子图案:master

搭建环境:
将 Node & npm bin/ 文件夹提供到 PATH: NodeJS 路径
npmrc 文件:系统默认

构建:
命令:
回显$PATH
节点--版本
npm --版本
npm install -g @angular/cli
构建

当我提交代码或重新验证时,构建会被触发,但它会获取先前的提交,而不是触发构建的最新提交。

以下是构建日志:

10:55:56 Cloning the remote Git repository      
10:55:56 Cloning repository ssh://rmp-bot@***       
10:55:56  > git init /var/lib/jenkins/workspace/application_name/Patchset-Sonar-CI-master # timeout=10          
10:55:56 Fetching upstream changes from ssh://rmp-bot@***             
10:55:56  > git --version # timeout=10        
10:55:56 using GIT_SSH to set credentials Gerrit ssh user              
10:55:56  > git fetch --tags --progress ssh://rmp-bot@***   +refs/heads/*:refs/remotes/origin/*                           
10:55:57  > git config remote.origin.url ssh://rmp-bot@*** # timeout=10
10:55:57  > git config --add remote.origin.fetch +refs/heads/*:refs/remotes/origin/* # timeout=10            
10:55:57  > git config remote.origin.url ssh://rmp-bot@*** # timeout=10           
10:55:57 Fetching upstream changes from ssh://rmp-bot@***        
10:55:57 using GIT_SSH to set credentials Gerrit ssh user               
10:55:57  > git fetch --tags --progress ssh://rmp-bot@***  +refs/heads/*:refs/remotes/origin/*                   
10:55:57  > git rev-parse refs/remotes/origin/master^{commit} # timeout=10          
10:55:57  > git rev-parse refs/remotes/origin/origin/master^{commit} # timeout=10                
10:55:57 Checking out Revision fc96e9e083c368ff963114914fede303d885ae6a (refs/remotes/origin/master)           
10:55:57  > git config core.sparsecheckout # timeout=10                 
10:55:57  > git checkout -f fc96e9e083c368ff963114914fede303d885ae6a 

不同项目类型的设置适用于其他应用程序 Jenkins 设置。请告诉我上述配置出了什么问题。

我还尝试在 SCM -> Git -> 存储库中添加 Refspec: refs/changes/:refs/changes/ & Name: origin 。但仍然面临同样的问题。

git jenkins jenkins-plugins jenkins-pipeline
4个回答
1
投票

要解决此问题,请将前缀“origin”添加到要构建的分支。 像这样:

Branches to build: origin/master

1
投票

这基本上是由工作区中的一些缓存引起的。

有几个选项可以解决这个问题。

  1. 在 git checkout 阶段之前删除/清理工作区。 Jenkins
    Delete workspace before build starts
    的作业配置中有一个选项。此选项位于自由式作业中的“构建环境”下。
  2. 正如 mkebri 在他们的回答中提到的.. 在分支名称中添加
    origin/
    前缀。这告诉 git 使用
    remote
    分支。
  3. 在作业的 Git 部分的附加行为选项中,您可以添加“擦除存储库并强制克隆”,这与选项一类似。
  4. 有可用的插件也可以为您做这些事情

0
投票

通过在 SCM -> Git -> 存储库中为 Refspec: refs/changes/:refs/changes/ 提供正确的值来解决此问题。


0
投票

正如 mkebri 所说,编辑项目配置 -> SCM -> 分支来构建会有所帮助。要构建任何分支,您可以添加:

origin/*
© www.soinside.com 2019 - 2024. All rights reserved.