首页 > 解决方案 > 詹金斯无法在 git repo 中找到目录

问题描述

我已经在我的 ubuntu 机器上的 ssh 服务器上安装了 jenkins。我创建了一个构建 C++ 项目的工作。

该作业执行 shell 命令:

cd exact-arithmetic/
qmake exact-arithmetic.pro
make

当作业建立时,我收到以下错误

Building in workspace /var/lib/jenkins/workspace/integerBuild
Cloning the remote Git repository
Cloning repository REPONAME
 > git init /var/lib/jenkins/workspace/integerBuild # timeout=10 
Fetching upstream changes from REPONAME
 > git --version # timeout=10
using GIT_ASKPASS to set credentials 
 > git fetch --tags --progress REPONAME +refs/heads/*:refs/remotes/origin/*
 > git config remote.origin.url REPONAME # timeout=10
 > git config --add remote.origin.fetch +refs/heads/*:refs/remotes/origin/* # timeout=10
 > git config remote.origin.url REPONAME # timeout=10
Fetching upstream changes from REPONAME
using GIT_ASKPASS to set credentials 
 > git fetch --tags --progress REPONAME +refs/heads/*:refs/remotes/origin/*
 > git rev-parse refs/remotes/origin/master^{commit} # timeout=10
 > git rev-parse refs/remotes/origin/origin/master^{commit} # timeout=10
Checking out Revision d1d90929149a6de918bae21bdc6710c1965a81a5 (refs/remotes/origin/master)
 > git config core.sparsecheckout # timeout=10
 > git checkout -f d1d90929149a6de918bae21bdc6710c1965a81a5
Commit message: "Peronalisation files for git"
 > git rev-list --no-walk d1d90929149a6de918bae21bdc6710c1965a81a5 # timeout=10
[integerBuild] $ /bin/sh -xe /tmp/jenkins5258842808869431608.sh
+ cd exact-arithmetic/
/tmp/jenkins5258842808869431608.sh: 2: cd: can't cd to exact-arithmetic/
Build step 'Execute shell' marked build as failure
[WS-CLEANUP] Deleting project workspace...[WS-CLEANUP] done
Finished: FAILURE

詹金斯连接到回购没有问题。当我查看 github 存储库时,我看到目录精确算术存在。

但是,我已经运行了一个执行命令行 ls 的作业,并且我的目录都没有出现。我不确定我做错了什么,并且似乎找到了很多有用的信息。

任何帮助表示赞赏。

标签: gitubuntujenkins

解决方案


从您的评论中:

  • ls返回一个空文件夹
  • pwd返回您当前的工作区:/var/lib/jenkins/workspace/integerBuild

您的文件夹exact-arithmetic/不存在。

要创建它,您可以在流程中添加命令:

mkdir -p exact-arithmetic/

仅当文件夹尚不存在时才会创建该文件夹。它将解决您的错误,但您将无法构建。

我的猜测是您的来源尚未在您的 git 工作流程中克隆。

我建议你git init

git clone https://github.com/USERNAME/REPOSITORY.git

Git init创建一个新的仓库。但git clone会得到你现有回购的来源。git fetch将获得您想要测试的更改。


推荐阅读