Jenkins pipeline如何更改到另一个文件夹并运行npm测试

kqlmhetl  于 2022-11-21  发布在  Jenkins
关注(0)|答案(2)|浏览(452)

目前,我正在使用Jenkins管道脚本。
为了运行我的测试,我需要访问桌面上的代码。
我试过这个:

pipeline {
  agent any

  tools {nodejs "node"}

  stages {
    stage('Tests') {
      steps {
        sh 'cd users/tests/'
        sh 'npm run shopfloor.shopfloor'
      }
    }
  }
}

如何更改到我的测试文件夹,然后运行“npm run test”
我尝试了下面的答案,但我现在得到这个错误:

Running in users/tests/
[Pipeline] {
[Pipeline] sh
shell-init: error retrieving current directory: getcwd: cannot access parent directories: Operation not permitted
+ npm run shopfloor.shopfloor
job-working-directory: error retrieving current directory: getcwd: cannot access parent directories: Operation not permitted
Error: EPERM: operation not permitted, uv_cwd
    at process.wrappedCwd (internal/bootstrap/switches/does_own_process_state.js:129:28)
    at process.cwd (/Users/.jenkins/tools/jenkins.plugins.nodejs.tools.NodeJSInstallation/node/lib/node_modules/npm/node_modules/graceful-fs/polyfills.js:10:19)
    at Conf.loadPrefix (/Users/.jenkins/tools/jenkins.plugins.nodejs.tools.NodeJSInstallation/node/lib/node_modules/npm/lib/config/load-prefix.js:46:24)
    at load_ (/Users/.jenkins/tools/jenkins.plugins.nodejs.tools.NodeJSInstallation/node/lib/node_modules/npm/lib/config/core.js:109:8)
    at Conf.<anonymous> (/Users/.jenkins/tools/jenkins.plugins.nodejs.tools.NodeJSInstallation/node/lib/node_modules/npm/lib/config/core.js:96:5)
    at Conf.emit (events.js:315:20)
    at ConfigChain._resolve (/Users/.jenkins/tools/jenkins.plugins.nodejs.tools.NodeJSInstallation/node/lib/node_modules/npm/node_modules/config-chain/index.js:281:34)
    at ConfigChain.add (/Users/.jenkins/tools/jenkins.plugins.nodejs.tools.NodeJSInstallation/node/lib/node_modules/npm/node_modules/config-chain/index.js:259:10)
    at Conf.add (/Users/.jenkins/tools/jenkins.plugins.nodejs.tools.NodeJSInstallation/node/lib/node_modules/npm/lib/config/core.js:338:27)
    at Conf.<anonymous> (/Users/.jenkins/tools/jenkins.plugins.nodejs.tools.NodeJSInstallation/node/lib/node_modules/npm/lib/config/core.js:314:25)
internal/bootstrap/switches/does_own_process_state.js:129
    cachedCwd = rawMethods.cwd();
mum43rcc

mum43rcc1#

使用dir步骤切换目录并在该上下文中执行命令:

pipeline {
  agent any

  tools {nodejs "node"}

  stages {
    stage('Tests') {
      steps {
        dir('users/tests/') { // <<------------
          sh 'npm run shopfloor.shopfloor'
        }
      }
    }
  }
}
2g32fytz

2g32fytz2#

请使用双引号再试一次。

dir("folder")

在Groovy中,单引号是标准的Java字符串,而双引号是可模板化的字符串。

相关问题