gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-05 09:10:48 24 4
gpt4 key购买 nike

目前,我正在使用 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();

最佳答案

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

pipeline {
agent any

tools {nodejs "node"}

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

关于Jenkins 管道如何更改到另一个文件夹并运行 npm 测试,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60904267/

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