Jenkins 管道无法识别我的 Angular 项目

问题描述 投票:0回答:2

我正在开发一个结构更复杂的项目,如下所示: '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 ver. 2.222.3; 
Angular CLI: 8.3.18; 
Node: 12.13.0; 
OS: linux x64

如果我尝试从 CLI 运行相同的命令,它会起作用。这可能是什么原因?

angular linux jenkins npm jenkins-pipeline
2个回答
0
投票

无论你做什么都是正确的,唯一的是:你可能会错过 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"
                }
            }
        }
    }
}

0
投票

我按照您的建议通过调试成功解决了这个问题。找到问题并解决了。它在错误的文件夹中运行,因为我指向了错误的文件夹,而一开始似乎没问题。 所以这基本上是我的问题,通过指向一个类似的文件夹。 谢谢您的帮助。

最新问题
© www.soinside.com 2019 - 2024. All rights reserved.