gpt4 book ai didi

azure-devops - 使用 SonarCloud 和 Azure DevOps 分析 Javascript/Typescript 项目

转载 作者:行者123 更新时间:2023-12-04 10:45:23 24 4
gpt4 key购买 nike

我有一个包含 Javascript 和 Typescript 文件的项目。我正在使用 SonarCloud 从 Azure DevOps 管道分析这个项目。

我在构建管道中设置任务准备分析配置,如下所示:

- task: SonarCloudPrepare@1
inputs:
SonarCloud: 'Sonarcloud'
organization: 'MyOrg'
scannerMode: 'CLI'
configMode: 'manual'
cliProjectKey: 'My key'
cliProjectName: 'My name'
cliSources: '.'

运行管道时,我在 Sonar Cloud Analyze 步骤的管道中出现以下错误
INFO: Found 1 tsconfig.json file(s): [/home/vsts/work/1/s/tsconfig.json]
##[error]ERROR: Cannot find module 'typescript'
##[error]ERROR: TypeScript dependency was not found and it is required for analysis.
ERROR: Install TypeScript in the project directory or use NODE_PATH env. variable to set TypeScript location, if it's located outside of project directory.

ERROR: TypeScript dependency was not found and it is required for analysis.
ERROR: Install TypeScript in the project directory or use NODE_PATH env. variable to set TypeScript location, if it's located outside of project directory.
##[error]ERROR: Missing TypeScript dependency

该分析适用于 javascript 文件,但不适用于 typescript 文件。我在 package.json 中将 typescript 包安装为 dev 依赖项,但它似乎被 SonarCloud 忽略了。

我发现的文档和主题与 SonarQube 版本相关,但我不知道如何使用 SonarCloud 进行设置。

最佳答案

默认情况下,node_modules如果您使用的是 Visual Studio,则不会将本地项目文件夹中的文件夹添加到源代码管理中。

而这个错误自 Run Code Analysis 起就会发生任务找不到您 package.json 中定义的依赖包文件。我可重复的步骤:

enter image description here

然后我加一个 npm install之前的任务Prepare Analysis task安装缺少的软件包:

enter image description here

NodeJS 是我的项目名称。同样在 Devops 存储库中,这是 package.json 所在文件夹的名称。

然后这个问题在我的管道中消失了:

enter image description here

希望它也有助于您的问题:)

另外:您也可以选择添加本地 node_modules如果需要,文件夹进入源代码管理。但这是不推荐 在 Azure DevOps 服务中。

关于azure-devops - 使用 SonarCloud 和 Azure DevOps 分析 Javascript/Typescript 项目,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59730543/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com