如何使用 Jenkins 运行 nodeJS 测试

时间:2021-01-07 08:11:58

标签: jenkins jenkins-pipeline

我正在了解 Jenkins CI 并使用管道来安排我的工作。在我的测试没有运行的情况下,我遇到了停顿。请查看我的“Jenkins 图片”链接。如您所见,它卡在 --coverage 表中。通常,如果我要在本地计算机上运行测试,则必须输入 w 命令才能让节点运行所有测试;但是,我认为在 jenkins 环境中会有所不同

Jenkins Image

詹金斯档案

def gv

pipeline {
    agent any
    tools {nodejs "node"}
    parameters {
        choice(name: 'VERSION', choices: ['1.1.0', '1.2.0', '1.3.0'], description: '')
        booleanParam(name: 'executeTests', defaultValue: true, description: '')
    }
    stages {
        stage("init") {
            steps {
                script {
                   gv = load "script.groovy"
                   CODE_CHANGES = gv.getGitChanges()
                }
            }
        }
        stage("build frontend") {
            steps {
                dir("client") {
                    sh 'npm install'
                    echo 'building client'
                }
            }
        }
        stage("build backend") {
            steps {
                dir("server") {
                    sh 'npm install'
                    echo 'building server...'
                }
            }
        }
        stage("test") {
            when {
                expression {
                    script {
                        env.BRANCH_NAME.toString().equals('feature-jenkins') && CODE_CHANGES == false
                    }
                }
            }
            steps {
                dir("/client") {
                    sh 'npm test'
                    echo 'testing application'
                }
            }
        }
        stage("deploy") {
            steps {
                script {
                    gv.deployApp()
                }
            }
        }
    }   
}

0 个答案:

没有答案
相关问题