须藤:找不到命令|gitlab-ci [英] sudo: command not found | gitlab-ci

查看:81
本文介绍了须藤:找不到命令|gitlab-ci的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在我的简单项目中使用了 gitlab-ci.

I'm using gitlab-ci for my simple project.

一切正常,我的跑步者正在我的本地机器(ubuntu18-04)上工作,我用简单的 .gitlab-ci.yml 对其进行了测试.

And everything is ok my runner is working on my local machine(ubuntu18-04) and I tested it with simple .gitlab-ci.yml.

现在我尝试使用以下 yml:

Now I try to use the following yml:

image: ubuntu:18.04 

build-job:
  stage: build
  script:
    - echo "Hello, $GITLAB_USER_LOGIN!"
    - sudo apt-get update

但我收到以下错误:

/bin/bash: line 110: sudo: command not found

如何使用 sudo?

推荐答案

您不必担心更新 Gitlab CI 管道作业中使用的 Ubuntu 映像,因为作业完成后 docker 容器会被销毁.此外,docker 镜像经常更新.如果你查看 ubuntu:18.04 的 docker hub 页面,它在 2 天前刚刚更新:https://hub.docker.com/_/ubuntu?tab=tags&page=1&ordering=last_updated

You shouldn't have to worry about updating the Ubuntu image used in a Gitlab CI pipeline job because the docker container is destroyed when the job is finished. Furthermore, the docker images are frequently updated. If you look at ubuntu:18.04's docker hub page, it was just updated 2 days ago: https://hub.docker.com/_/ubuntu?tab=tags&page=1&ordering=last_updated

由于您正在此处进行更新,因此我假设接下来您可能想要安装一些软件包.这样做是可能的,但不建议这样做,因为您运行的每个管道都必须安装这些包,这确实会减慢它们的速度.相反,您可以基于父映像创建自定义 docker 映像并以这种方式对其进行自定义.然后,您可以将该 docker 镜像上传到 docker hub、Gitlab 的注册表(如果使用自托管的 Gitlab,则必须由管理员启用),或者在您的所有 gitlab-runner 上构建.

Since you're doing an update here, I'm going to assume that next you might want to install some packages. It's possible to do so, but not advised since every pipeline that you run will have to install those packages, which can really slow them down. Instead, you can create a custom docker image based on a parent image and customize it that way. Then you can either upload that docker image to docker hub, Gitlab's registry (if using self-hosted Gitlab, it has to be enabled by an admin), or built on all of your gitlab-runners.

这是一个愚蠢的例子:

# .../custom_ubuntu:18.04/Dockerfile
FROM ubuntu:18.04
RUN apt-get install git

接下来你可以构建镜像:docker build/path/to/directory/that/has/dockerfile,标记它以便你可以在你的管道配置文件中引用它:docker tagaaaaafffff59 my_org/custom_ubuntu:18.04.然后,如果需要,您可以上传标记的图像 docker push my_org/custom_ubuntu:18.04.

Next you can build the image: docker build /path/to/directory/that/has/dockerfile, tag it so you can reference it in your pipeline config file: docker tag aaaaafffff59 my_org/custom_ubuntu:18.04. Then if needed you can upload the tagged image docker push my_org/custom_ubuntu:18.04.

在您的 .gitlab-ci.yml 文件中,引用此自定义 Ubuntu 映像:

In your .gitlab-ci.yml file, reference this custom Ubuntu image:

image: my_org/custom_ubuntu:18.04 

build-job:
  stage: build
  script:
    - echo "Hello, $GITLAB_USER_LOGIN!"
    - git --version # ensures the package you need is available

您可以在此处阅读有关在 Gitlab CI 中使用自定义图像的更多信息:https://docs.gitlab.com/charts/advanced/custom-images/

You can read more about using custom images in Gitlab CI here: https://docs.gitlab.com/charts/advanced/custom-images/

这篇关于须藤:找不到命令|gitlab-ci的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆