Gitlab Runner无法在Powershell执行器中检索依赖项repo



CI Runner Context

  • Gitlab版本:13.12.2(私有服务器)
  • Gitlab Runner版本:14.9.1
  • 执行器:shell执行器(PowerShell)
  • 开发系统:Windows 10
  • Python项目(可能不相关)
  • (使用Poetry进行依赖管理)

问题我正在为一个项目设置一个自动集成系统,该项目有几个内部依赖关系,托管在与正在集成的项目相同的服务器上。如果我在yml文件中运行带有poetry update的CI,作业控制台将发送一个错误码为128的退出。在我的内部依赖上调用git克隆时。

为了隔离这个问题,我尝试简单地调用同一个repo上的git clone。响应是运行程序无法向Gitlab服务器验证自己。

我已经尝试过的

通过阅读Gitlab文档,我发现运行程序需要授权才能拉取任何私有依赖项。为此,Gitlab创建了部署键。

因此,我按照说明为依赖项创建部署键并将其添加到子项目的部署键列表中。然后我又遇到了完全相同的权限问题。

我错过了什么?

(对于在windows PowerShell中寻找这种情况的任何人来说,运行程序使用的用户是nt authority/system,这是一个系统用户,我还没有找到像人类一样访问它的方法。我必须让CI运行器执行ssh密钥创建步骤。)

<<p>例子em> .gitlab-ci。yml文件:
#Commands in PowerShell
but_first:
#The initial stage, always happens first
stage: .pre
script:
# Start ssh agent for deploy keys
- Start-Service ssh-agent
# Check if ssh-agent is running
- Get-Service ssh-agent
- git clone ssh://git@PRIVATE_REPO/software/dependency-project.git

我解决了通过拉取内部依赖的问题,完全绕过了源代码的ssh拉取,并通过从诗歌切换到hatch进行依赖管理(我将在后面解释为什么)。

托管编译后的依赖项

为此,我将我的依赖项目的源代码编译成一个发布就绪的包(在这里它是一个python wheel)。然后使用Gitlab的包和注册表来托管我的包。我没有在每个源代码项目中都有包,而是将所有依赖项的包推送到我为这个单一目的创建的项目中。

我.gitlab-ci。当发布到该项目时,Yaml文件看起来像这样:

deploy:
# Could be used to build the code into an installer
stage: Deploy
script:
- echo "deploying"
- hatch version micro
# only wheel is built (without target, both wheel and sdist are built)
- hatch build -t wheel
- echo "Build done ..."
- hatch publish --repo http://<private gitlab repo>/api/v4/projects/<project number>/packages/pypi --user gitlab-ci-token --auth $CI_JOB_TOKEN
- echo "Publishing done!"

拉出宿主依赖(&为什么我抛弃了诗歌)

我的第一个问题是让pip找到包含我所有包的额外的pypi存储库。但是皮普已经有解决办法了!

在它的pip.ini文件中(要找到它的位置,可以执行pip config -v list),需要添加2个条目:

[global]
extra-index-url = http://__token__:<your api token>@<private gitlab repo>/api/v4/projects/<project number>/packages/pypi/simple
[install]
trusted-host = <private gitlab repo>

这使得它在功能上与在调用pip install时添加——extra-index-url——trusted-host标签相同。

由于我使用的是依赖管理器,所以我没有直接使用pip,而是使用管理器对pip的包装器。这就是我决定改变依赖管理器的主要原因:诗歌无法读取或识别pip.ini。因此,在这些文件中所做的任何更改都将被忽略。

使用pip.ini文件的配置,我在私有包repo中的任何依赖项也将被搜索以安装项目。下面这行:

- git clone ssh://git@PRIVATE_REPO/software/dependency-project.git

变成简单的一行:

- pip install dependency-project

或pyproject.toml:

中的一行dependencies = [

"dependency-project"

"second_project"

)

最新更新