我有以下 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
> <a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="b5d6c0c6c1dad8d0c798c2d0d7c5dac7c1d4d998d3d0f5849b859b87" rel="noreferrer noopener nofollow">[email protected]</a> 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
是在单独的作业中完成的,并且该文件夹作为工件传递。添加 npm install
命令以防万一,直接添加到此作业中,也没有解决问题。
更新2: 我已将本地计算机注册为运行程序并尝试在其上运行作业。
我在top
中看到,当作业到达ng lint
命令时,node
进程运行了一小段时间,然后消失(希望意味着命令已完成)然后整个运行者就永远挂起,让我的电脑处于空闲状态。
.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": {}
}
]
}
最佳答案
我正在使用的完整 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。它基本上运行复制命令( <goal>copy-resources</goal>
),并从 frontend/src/main/resources/ngapp
复制项目。至fronted/ngapp
文件夹(以及准备部署包的其他内容)。我们使用了很长一段时间都没有问题,但是升级到 Angular 17 后,由于某种原因,出现了问题。
替换 cd frontend/ngapp
与 frontend/src/main/resources/ngapp
(因此,在项目的原始位置而不是在复制的文件夹中运行 ng lint
命令解决了该问题。
在项目所在的原始文件夹上运行完全相同的作业,运行成功。我们不确定为什么(尝试了不同的缓存策略;我们在新文件夹中运行 npm install 等),但它解决了问题,并且不再卡住。
关于node.js - Gitlab 运行程序在运行 lint 命令时超时,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/77690462/