ci/cd 管道中缺少 yamllint 包

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

我正在运行这段 CI/CD 代码。运行程序在 intel MAC 上运行,执行程序是 shell。不知道我错过了什么。当我在本地运行相同的图像并登录到它时,我能够找到包 yamllint,但是当它通过管道运行时,我不断收到: ” 正在阅读包装清单... 构建依赖树... 正在读取状态信息... E:无法找到包 yamllint ”

Code-Check:
  stage: code-check
  variables:
    DOCKER_IMAGE: "python:3.8-slim"
  image: $DOCKER_IMAGE
  script:
    - docker run -v $(pwd):/app -w /app $DOCKER_IMAGE apt-get update -qy
    - docker run -v $(pwd):/app -w /app $DOCKER_IMAGE apt install yamllint
    - docker run -v $(pwd):/app -w /app $DOCKER_IMAGE yamllint . --strict > yamllint_report.txt || true
    - docker run -v $(pwd):/app -w /app $DOCKER_IMAGE find . -name "*.py" -exec bandit -r {} \; > bandit_report.txt || true
    - cat yamllint_report.txt
    - cat bandit_report.txt
  only:
    - branches
docker gitlab continuous-integration gitlab-ci
1个回答
0
投票

像这样设置

.gitlab-ci.yml

stages:
  - code-check

code-check:
  image: python:3.8-slim
  stage: code-check
  script:
    - apt-get update -qq -y
    - apt install -qq -y yamllint
    - pip install bandit
    - yamllint . --strict > yamllint_report.txt || true
    - find . -name "*.py" -exec bandit -r {} \; > bandit_report.txt || true
    - cat yamllint_report.txt
    - cat bandit_report.txt

在您的版本中,每个步骤都在单独的 Docker 容器中进行。因此,您在一个容器中安装了

yamllint
,然后尝试在另一个容器(尚未安装它)中运行它。

通过这种方法,一切都发生在一个容器中。

这是直接从 Gitlab 记录下来的工作流程的结尾:

© www.soinside.com 2019 - 2024. All rights reserved.