jenkins - ws() 如何在 Jenkins groovy 中工作?
问题描述
情况1
下面的脚本管道代码workSpace
用作 npm 构建过程的工作区,npm install
可以在其中找到package.json
文件workSpace
ws(workSpace){
def commandString = "npm install ; npm rebuild node-sass ; ng build"
executeCommand(commandString, repositoryName)
}
在哪里executeCommand()
,
def executeCommand(commandString, component){
BUILD_FULL = sh (
script: commandString,
returnStatus: true
) == 0
echo " Build status for ${component}: ${BUILD_FULL}"
}
案例2
但是,下面的代码与workSpace
用于 npm 构建过程的工作区相同,但npm install
无法package.json
在workSpace
ws(workSpace){
buildStatus = sh (
returnStdout: true,
script: '''
npm install // Install dependencies
npm rebuild node-sass // Convert scss to css native
ng build --prod --configuration=cloud // Build
'''
) == 0
print "User@ Build status for ${repositoryName} is ${buildStatus}"
} // end ws()
以下是案例 2 中的错误
+ npm install // Install dependencies
npm ERR! code ENOLOCAL
npm ERR! Could not install from "../../../../../.." as it does not contain a package.json file.
npm ERR! A complete log of this run can be found in:
npm ERR! /home/jenkins/.npm/_logs/2019-01-07T16_20_20_339Z-debug.log
如何ws()
在 groovy 中工作?
解决方案
您应该删除注释并用管道替换它们以在另一个完成后运行任务
sh '''
npm install ||
npm rebuild node-sass ||
ng build --prod --configuration=cloud
'''
让我知道是否有效!
推荐阅读
- protocol-buffers - 如何使 protobuf 不区分大小写?
- vba - Excel VBA - 如何使用 ByVal
- python - 避免大型 Pandas DataFrame 上 GroupBy 的内存问题
- java - 我如何将 JProgressBar 放入 java 中的 JOptionPane 中?
- ios - 在 iOS 上以编程方式设置“音频音量平衡”
- web-parts - Kentico “可编辑的 Web 部件”出现在“编辑区域和 Web 部件”下的页面中
- typescript - 如何使用 let x: type | 避免嵌套的 typescript if 语句 未定义 = 变量
- c# - C# - 将一个类克隆为一个动态的
- python - 使用 Py_SetPath() 让 Python 在不同的位置查找 Lib
- delphi - Delphi【查找声明】使用OTA