我正在处理一个具有更复杂结构的项目,如下所示:'rootFolder/frontendParentFolder/actualAngularProject‘
我有一个Jenkins作业,它尝试为angular项目运行代码覆盖率任务。
我现在的步骤是这样的:
stage('Testing Front End') {
steps {
echo 'Running front end tests...'
dir('frontendParentFolder/actualAngularProject') {
sh 'ng test --code-coverage --watch=false'
}
}
}Jenkins工作执行签出、构建和其他工作,它显然是从项目的根开始的。当它走到这一步时,它会这样说...
[Pipeline] }
[Pipeline] // stage
[Pipeline] stage
[Pipeline] { (Testing Front End)
[Pipeline] tool
[Pipeline] envVarsForTool
[Pipeline] tool
[Pipeline] envVarsForTool
[Pipeline] withEnv
[Pipeline] {
[Pipeline] echo
Running front end tests...
[Pipeline] dir
Running in /home/jenkins/workspace/rootFolder/frontendParentFolder/actualAngularProject
[Pipeline] {
[Pipeline] sh
[actualAngularProject] Running shell script
+ ng test --code-coverage --watch=false
The test command requires to be run in an Angular project, but a project definition could not be found.
[Pipeline] }
[Pipeline] // dir
[Pipeline] }
[Pipeline] // withEnv
[Pipeline] }
[Pipeline] // stage
[Pipeline] }
[Pipeline] // withEnv
[Pipeline] }我还试着提到了项目的名称,比如sh 'ng test actualAngularProject --code-coverage --watch=false‘,但我还是得到了同样的结果。我试图安装NPM插件,但我不知道如何使用它,也没有找到合适的示例。
我有: Jenkins版本。2.222.3;Angular命令行界面: 8.3.18;Node: 12.13.0;操作系统: linux x64
如果我尝试从CLI运行相同的命令,它可以工作。这可能是什么原因呢?
发布于 2020-12-25 01:59:49
无论您做什么都是正确的,唯一的问题是:您可能会错过angular项目文件夹的实际路径。下面的示例说明了一些与您的示例类似的内容,将帮助您进行调试并找到根本原因
pipeline {
agent any;
stages {
stage("create folder & file for debug") {
steps {
deleteDir()
sh """
mkdir -p a/b/c
echo "Hello , I am from folder C" >> a/b/c/c.txt
"""
}
}
stage("debug") {
steps {
sh """
ls -al a
ls -al a/b
ls -al a/b/c
cat a/b/c/c.txt
"""
dir('a/b/c') {
sh "cat c.txt"
}
// or
dir("${env.WORKSPACE}/a/b/c") {
sh "cat c.txt"
}
}
}
}
}发布于 2021-01-04 18:06:22
我按照您的建议通过调试解决了这个问题。找到了问题并解决了它。它是在错误的文件夹中运行的,因为我指向了错误的文件夹,这在一开始似乎是正常的。所以这基本上是我的问题,通过指向一个类似的文件夹。谢谢你的帮助。
https://stackoverflow.com/questions/65427349
复制相似问题