如何在 gitlab ci/cd 管道中的 r 包中启用 linting

How to enable linting in r package in gitlab ci/cd pipeline

我已经在 gitlab 中为 r-package 创建了 CI 管道。如果有任何 lint 错误,我需要捕获 lint 输出并使作业失败。我无法读取 lintr 命令的输出。

image: r-base:4.1.2

stages:
  - LintR

LintR:
  stage: LintR
  script:
    - cd .. 
    - R -e "capture.output(lintr::lint_package(\"./test-r/\"), file=\"./lint_output.txt\")"
    - cd isp-r && mv ../lint_output.txt .
  artifacts:
    paths:
      - ./lint_output.txt
    when: always

如何在gitlab中捕获输出CI/CD

尝试以下操作:

image: r-base:4.1.2

stages:
  - LintR

LintR:
  stage: LintR
  script:
    # redirect lintr stdout and stderr to file
    - CI="" R -e "lintr::lint_package()" &> lint_output.txt 
    # fail if file is not empty
    - [ ! -s lint_output.txt ]
  artifacts:
    paths:
      - lint_output.txt