Gitlab任务失败(sudo:命令未找到或获取失败)

4
我正在使用 Gitlab Jobs 来部署一个工具。下面的代码会返回 sudo: command not found。如果我删除 sudo,将得到以下结果:
W: Failed to fetch http://deb.debian.org/debian/dists/stable/InRelease  Could not connect to deb.debian.org:80 (199.232.138.132), connection timed out
W: Failed to fetch http://security.debian.org/debian-security/dists/stable-security/InRelease  Could not connect to security.debian.org:80 (151.101.130.132), connection timed out Could not connect to security.debian.org:80 (151.101.66.132), connection timed out Could not connect to security.debian.org:80 (151.101.2.132), connection timed out Could not connect to security.debian.org:80 (151.101.194.132), connection timed out
W: Failed to fetch http://deb.debian.org/debian/dists/stable-updates/InRelease  Unable to connect to deb.debian.org:80:
W: Some index files failed to download. They have been ignored, or old ones used instead.
Reading package lists...
Building dependency tree...
Reading state information...
E: Unable to locate package latex209-bin
E: Unable to locate package texlive-latex-base
E: Unable to locate package texlive-latex-extra
E: Unable to locate package ant
Cleaning up project directory and file based variables
00:01
ERROR: Job failed: exit code 1

这是.gitlab-ci.yml文件:
stages:
  - deploy
variables:
  RA_NAME: "My_project"
default:
  before_script:
    - sudo apt-get update -qq && sudo apt-get install -y latex209-bin texlive-latex-base texlive-latex-extra ant && sudo apt-get install zip unzip
    
deploy_Default:
  stage: deploy
  script:
    - sh -x deploy.sh "$RA_NAME" "$(cat RA_VERSION)"
  artifacts:
    paths:
      - "${RA_NAME}_$(cat RA_VERSION).zip"
  only:
    - master
    - dev
    - tags

发生了一周的问题(很可能是由于Gitlab 15.0发布引起的)。在此之前,每个作业都毫无问题地“通过”了。现在,在不更改任何内容的情况下,它们全部失败(甚至尝试重新运行旧的“通过”作业也是如此)。
我尝试添加了一些内容。
build_image:
  script:
    - docker build --network host

我尝试了一些类似的配置,但都没有起作用。

现在我的问题是:为什么sudo没有再像以前那样工作了,而我并没有更改.gitlab-ci.yml文件呢?我应该怎么做才能解决这个问题。
需要提到的是,这些作业是由only中提到的分支的提交触发的。我可以通过运行pipeline或重新运行已经运行过的作业来运行它们。我不知道还有其他的运行方式。所有与Gitlab和Docker相关的工作都是通过Gitlab UI完成的。


你尝试更新你的GitLab Runner了吗? - GChuf
嗨,@alexandru-dudu!你能提供一些关于Gitlab安装的系统信息吗?它是自托管的吗?我觉得这可能是Debian系统上的更改引起的。 - SvenTUM
嗨。除了我上面的代码和UI界面,我没有访问任何东西。我以为这是由于Debian更新,但我不确定如何修复它,因为我对gitlab实例没有任何权限。我在想也许有一个替代我现有代码的选择... - Alexandru DuDu
2个回答

1
我已经解决了这个问题。在更新之前,我没有在.gitlab-ci.yml中指定任何图像时,默认使用了我的公司Docker镜像enter image description here

更新后,我注意到它使用了另一种enter image description here

我在我的.gitlab-ci.yml中添加了以下内容:
image: myCompanyImage

现在它可以像以前一样正常工作。
如果你遇到这样的问题,请检查所使用的图像以及之前成功运行的管道中使用的图像。


2
你还有提升的空间。为什么需要在CI步骤中动态下载所有这些东西呢?我建议创建一个基础镜像,其中已经安装了所有依赖项,从而避免不必要的网络带宽以及潜在的问题,比如你遇到的那个问题。 - akortex
1
我是团队中唯一的开发人员,对于这些工具我没有使用经验。我正在学习,并且提高是我的主要目标之一。感谢您的建议。 - Alexandru DuDu

1
这种情况通常是由于实例/服务器存在网络问题所致。如果Runner不是自托管的,则GitLab应该很快解决此问题。如果Runner是自托管的,则可能存在网络问题。这里是我的建议:
注意:请尝试在没有sudo的情况下执行以下操作。
  1. Debian镜像站点列表中选择靠近您的地区的Debian镜像。
  2. 如果没有nano,请使用vi通过nano /etc/apt/sources.list编辑源列表。
  3. 更换为另一个镜像。
例如:
http://deb.debian.org/debian/dists/stable/InRelease // <-- remove this
http://ftp.us.debian.org/debian/dists/stable/InRelease // <-- add this
  1. 保存。

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接