我想运行一个利用漏洞扫描的GitLab CI管道(GitLab旗舰版).问题是我需要在构建阶段创建Package-lock.json文件.据我所知,如果文件在管道执行时不存在于存储库中,则作业(job)将不会执行.有人能帮我做这个吗?:)

NodeJS repo for building NPM packages. (not for building docker images)

在这个过程中,使用人工产物块并没有帮助我……

推荐答案

您可以覆盖扫描作业(job)的rules:,以消除锁定文件存在的需要.例如,来自内置依赖扫描模板的作业(job)gemnasium-dependency_scanning通常requires a lock file(例如**/yarn.lockpackage.lock.json)存在.但这是可以覆盖的.此外,您还可以添加对其他作业(job)的依赖关系,如生成锁定文件的作业(job),以确保生成的锁定文件存在于扫描作业(job)中(默认情况下,扫描作业(job)会忽略瑕疵).

include:
  - template: Jobs/Dependency-Scanning.gitlab-ci.yml

generate-lockfile:
  # ...
  stage: build
  # this is just an example...
  # update `script:` and `artifacts:` to your needs
  script:
    - yarn install --mode update-lockfile
  artifacts:
    paths:
      - yarn.lock

gemnasium-dependency_scanning:
  rules:  # override rules to not require lockfile to be committed
    - when: on_success
  dependencies: [generate-lockfile]  # download lockfile artifacts

This will ensure the scanning job is created in the pipeline even if you don't commit a lockfile and will also enable the job to download artifacts from a job where you produce your lockfile.
Just change the generate-lockfile job to whatever is necessary for generating your lockfile and expose it as an artifact.


当然,您可能希望一开始就提交一个锁定文件,但我想这不是这个问题的重点.

Node.js相关问答推荐

Azure虚拟机上的JS Express:可疑请求?

Spotify Auth访问令牌给出错误代码400

错误:找不到模块';/var/apps/前端/bash';

如何在Angular jest测试中调用Nodejs的垃圾收集? node v20的测试速度慢且内存泄漏

未显示NPM版本

后端如何保护数据不被用户提取其他用户的数据?

使用NodeJS通过服务账号列出Google Workspace用户

在 Nest 项目上运行 Jest 测试时,我的文件无法找到一个在测试之外没有任何问题的模块

在对象数组中的数组中嵌套 $lookup - Mongodb

为什么后端开发需要单独的服务器?

Mongodb 从文档中获取聚合结果中的特定属性

Google Calendar API FreeBusy 外部用户

如何使用来自前一阶段的另一个数组的聚合mongoose 在数组中添加字段

JavaScript & Node - 将图像文件保存到服务器但无法查看

NestJS TypeORM 可选查询不起作用

使用 $in 查询时,如何获取 mongoDB 中每个唯一 ID 的 n 个文档?

在本地运行 Cloud Functions 会出现错误functions.config() 不可用

如何使用 Node.js、Express 和 Mongoose 进行身份验证?

在 Jade 包含中使用变量

Javascript在try块内设置const变量