NodeJS Gitlab runner在运行lint命令时超时

3zwjbxry  于 11个月前  发布在  Node.js
关注(0)|答案(3)|浏览(124)

我有以下GitLab CI步骤:

lint:
  stage: frontend_check
  only:
    changes:
      - frontend/**/*
  script:
    - cd frontend/ngapp
    - npm run lint
    - npm run prettier

字符串
在GitLab上运行这个将在两个小时后超时。


的数据
原始日志:

[0KRunning with gitlab-runner 16.4.0 (6e766faf)[0;m
[0K  on runner-192.168.63.53 U-zL7nfx, system ID: s_351d454b0ffc[0;m
section_start:1702987831:prepare_executor
[0K[0K[36;1mPreparing the "docker" executor[0;m[0;m
[0KUsing Docker executor with image node:21.4.0 ...[0;m
[0KAuthenticating with credentials from /root/.docker/config.json[0;m
[0KPulling docker image node:21.4.0 ...[0;m
[0KUsing docker image sha256:b866e35a0dc4df85e168524b368567023eb22b06fe16f2237094e937fcd24d96 for node:21.4.0 with digest node@sha256:52206db44f7bb76dca465a9fae016922b6878c39261c87c9b719ae4d892fecfd ...[0;m
section_end:1702987834:prepare_executor
[0Ksection_start:1702987834:prepare_script
[0K[0K[36;1mPreparing environment[0;m[0;m
Running on runner-u-zl7nfx-project-425-concurrent-0 via gitlab-runner...
section_end:1702987835:prepare_script
[0Ksection_start:1702987835:get_sources
[0K[0K[36;1mGetting source from Git repository[0;m[0;m
[32;1mFetching changes with git depth set to 50...[0;m
Reinitialized existing Git repository in /builds/ivu/landshut/.git/
[32;1mChecking out b6b09e82 as detached HEAD (ref is master)...[0;m
Removing frontend/ngapp/

[32;1mSkipping Git submodules setup[0;m
section_end:1702987841:get_sources
[0Ksection_start:1702987841:download_artifacts
[0K[0K[36;1mDownloading artifacts[0;m[0;m
[32;1mDownloading artifacts for maven_compile (635434)...[0;m
Downloading artifacts from coordinator... ok      [0;m  host[0;m=gitlab.webvalto.hu id[0;m=635434 responseStatus[0;m=200 OK token[0;m=64_xgXce
[32;1mDownloading artifacts for install_dependencies (635435)...[0;m
Downloading artifacts from coordinator... ok      [0;m  host[0;m=gitlab.webvalto.hu id[0;m=635435 responseStatus[0;m=200 OK token[0;m=64_xgXce
section_end:1702987878:download_artifacts
[0Ksection_start:1702987878:step_script
[0K[0K[36;1mExecuting "step_script" stage of the job script[0;m[0;m
[0KUsing docker image sha256:b866e35a0dc4df85e168524b368567023eb22b06fe16f2237094e937fcd24d96 for node:21.4.0 with digest node@sha256:52206db44f7bb76dca465a9fae016922b6878c39261c87c9b719ae4d892fecfd ...[0;m
[32;1m$ cd frontend/ngapp[0;m
[32;1m$ npm run lint[0;m

> [email protected] lint
> ng lint --fix

Node.js version v21.4.0 detected.
Odd numbered Node.js versions will not enter LTS status and should not be used for production. For more information, please see https://nodejs.org/en/about/previous-releases/.
section_end:1702995031:step_script
[0K[31;1mERROR: Job failed: execution took longer than 2h0m0s seconds
[0;m


在具有相同Node版本的计算机上运行相同命令将在5秒内完成。


更新:npm install是在一个spearate job中完成的,文件夹作为工件传递。为了以防万一,将npm install命令直接添加到该job中,也没有解决问题。


**更新2:**我已将本地计算机注册为runner,并尝试在其上运行作业。

我在top中看到,当作业到达ng lint命令时,node进程运行了一小段时间,然后消失(希望意味着命令完成),然后整个运行程序永远挂起,使我的PC处于空闲状态。
.eslintrc.json

{
  "root": true,
  "ignorePatterns": ["projects/**/*"],
  "overrides": [
    {
      "files": ["*.ts"],
      "parserOptions": {
        "project": ["tsconfig.json", "e2e/tsconfig.json"],
        "createDefaultProgram": true
      },
      "extends": [
        "plugin:@angular-eslint/recommended",
        "plugin:@angular-eslint/template/process-inline-templates"
      ],
      "rules": {
        "@angular-eslint/component-selector": [
          "error",
          {
            "prefix": "app",
            "style": "kebab-case",
            "type": "element"
          }
        ],
        "@angular-eslint/directive-selector": [
          "error",
          {
            "prefix": "app",
            "style": "camelCase",
            "type": "attribute"
          }
        ]
      }
    },
    {
      "files": ["*.html"],
      "extends": ["plugin:@angular-eslint/template/recommended"],
      "rules": {}
    }
  ]
}

kiz8lqtg

kiz8lqtg1#

我使用的完整gitlab模板是:

image: node:21.4.0

stages:
  - maven_init # basic maven initialization
  - frontend_init # create frontend node environment for build
  - frontend_check # static checks before build
  - frontend_build # build the frontend app
  - pages # create documentation
  - test-server-deploy # deploy to test environment
  - e2e # isolated stage to test the currently deployed version on the  test server.
  - sonarqube-check # SonarQube code analysis

maven_compile:
  image: maven:latest
  needs: []
  stage: maven_init
  script:
    - mvn clean install -Ptest
  artifacts:
    paths:
      - ./frontend/ngapp/
  except:
    variables:
      - $RUN_E2E == "true"
      - $DEPLOY_TEST == "true"

lint:
  stage: frontend_check
  script:
    - cd frontend/ngapp
    - echo "Checking Angular CLI version..."
    - ng v
    - npm ci
    - echo "Running lint without rules/plugins..."
    # Temporarily disable rules/plugins here
    - CI=true ng lint
    - echo "Linting process completed or failed."
  cache:
    key: ${CI_COMMIT_REF_SLUG}-node-modules
    paths:
      - node_modules/

字符串
正如你所看到的,有一个步骤,首先运行maven install。它基本上运行一个copy命令(<goal>copy-resources</goal>),并将项目从frontend/src/main/resources/ngapp文件夹复制到fronted/ngapp文件夹(以及其他准备部署bundle的事情)。我们使用它很长一段时间都没有问题,但在升级到angular 17之后,由于某种原因,问题发生了。
cd frontend/ngapp替换为frontend/src/main/resources/ngapp(因此,在项目的原始位置运行ng lint命令,而不是在复制的文件夹中)解决了这个问题。
在项目所在的原始文件夹上运行完全相同的作业成功运行。我们不知道为什么(尝试了不同的缓存策略;我们在新文件夹中运行npm安装等),但它修复了这个问题,它不再卡住。

pdsfdshx

pdsfdshx2#

所以你有:

+-------------------+          +-------------------+
|                   |          |                   |
|   Local Machine   |   --->   |   GitLab Runner   |
|                   |          |                   |
| - Node.js v21.4.0 |          | - Docker Image    |
| - Linting: ~5 sec |          | - Node.js v21.4.0 |
|                   |          | - Linting: Timeout|
+-------------------+          +-------------------+

字符串
检查npm install是否在同一作业中运行,或者确保工件在作业之间正确传递。
有时linting规则或错误配置会导致linter进入无限循环。
此外,GitLab运行器可能有资源限制。检查分配给运行器的资源(CPU,内存)。为node_modules实现缓存以加快进程。临时增加超时设置以确定作业最终是否完成。
更新后的GitLab CI配置将是:

lint:
  stage: frontend_check
  only:
    changes:
      - frontend/**/*
  script:
    - cd frontend/ngapp
    - npm install # Make sure dependencies are installed
    - npm run lint
    - npm run prettier
  cache:
    paths:
      - node_modules/ # Cache node_modules
  artifacts:
    paths:
      - frontend/ngapp/ # Make sure artifacts are passed if `npm install` is in a separate job
  timeout: 4h # Temporarily increase the timeout


或者:

lint:
  image: node:current-lts # Use LTS version of Node.js
  stage: frontend_check
  only:
    changes:
      - frontend/**/*
  script:
    - cd frontend/ngapp
    - npm ci
    - CI=true npx ng lint # Use CI=true to mimic CI environment and npx to use local CLI
  cache:
    paths:
      - node_modules/


你的建议都不起作用,但是,我用你说的替换了命令。我将我的pc注册为GitLab runner(默认所有设置)并再次运行,结果相同。我在问题的结尾添加了新的屏幕截图。你还有其他建议吗?Runner进程没有显示任何有用的日志信息。
从评论中,确保Angular CLI版本(ng v)与package.json中指定的版本匹配检查是否将所有软件包更新到最新的兼容版本会有所帮助。
确定是否正在使用ESLint或TSLint。--verbose标志可能会提供给予更多线索,Node.js的详细日志记录可能会暴露文件访问问题或进程锁定。注意:ng lint没有详细选项,只有eslint plugin ' eslint-plugin-log-filenames '
注解掉lint规则和插件,然后一个接一个地重新引入它们,可以帮助识别是否是特定的配置导致了挂起。
清除本地缓存并运行npm ci以确保本地和CI中的状态都是干净的。检查是否在本地删除.angularnode_modules目录,测试可以帮助确定是否是陈旧或损坏的配置导致了问题。
如果进程挂起,则意味着Node.js进程或子进程仍在运行。检查正在运行的进程以查看它们正在做什么(进程名称,命令行参数等)。
.gitlab-ci.yml中使用cache keys来确保缓存被正确创建和恢复。

lint:
  stage: frontend_check
  script:
    - cd frontend/ngapp
    - echo "Checking Angular CLI version..."
    - ng v
    - npm ci
    - echo "Running lint without rules/plugins..."
    # Temporarily disable rules/plugins here
    - CI=true ng lint
    - echo "Linting process completed or failed."
  cache:
    key: ${CI_COMMIT_REF_SLUG}-node-modules
    paths:
      - node_modules/
  artifacts:
    paths:
      - frontend/ngapp/
  only:
    changes:
      - frontend/**/*


对于本地测试:

# Clear npm cache and remove directories
npm cache clean --force
rm -rf .angular node_modules

# Reinstall dependencies cleanly
npm ci

# Check running processes if linting hangs
ps aux | grep node

# Run linting
CI=true ng lint


作为mentioned by the OP,解决方案涉及更改运行ng lint命令的目录。通过在原始项目目录(frontend/src/main/resources/ngapp)而不是复制的目录(frontend/ngapp)中执行linting命令,成功解决了问题,linting进程不再挂起。
这确实突出了我在上面提出的一些观点,比如正确处理缓存和工件的重要性,以及确保CI中的环境和目录结构反映了本地设置的环境和目录结构:它有助于对文件和目录相关配置的调查。

vx6bjr1n

vx6bjr1n3#

我认为这是因为你还没有安装npm依赖项。所以ng命令是未知的。
尝试在以下情况下创建npm installnpm ci

lint:
 stage: frontend_check
 only:
   changes:
     - frontend/**/*
 script:
   - cd frontend/ngapp
   - npm install
   - npm run lint
   - npm run prettier

字符串
但也可以使用以前作业提供的缓存和工件,例如.npmnode_modules

相关问题