ws()在Jenkins groovy中是如何工作的? 案例1
下面的脚本化管道代码使用ws()在Jenkins groovy中是如何工作的? 案例1,jenkins,groovy,build,jenkins-pipeline,jenkins-groovy,Jenkins,Groovy,Build,Jenkins Pipeline,Jenkins Groovy,下面的脚本化管道代码使用工作区作为npm构建过程的工作区,其中npm安装能够在工作区中找到package.json文件 ws(workSpace){ def commandString = "npm install ; npm rebuild node-sass ; ng build" executeCommand(commandString, repositoryName) } ws(workSpace){
工作区
作为npm构建过程的工作区,其中npm安装
能够在工作区
中找到package.json
文件
ws(workSpace){
def commandString = "npm install ; npm rebuild node-sass ; ng build"
executeCommand(commandString, repositoryName)
}
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()
其中executeCommand()
为
def executeCommand(commandString, component){
BUILD_FULL = sh (
script: commandString,
returnStatus: true
) == 0
echo " Build status for ${component}: ${BUILD_FULL}"
}
案例2 但是,下面的代码与npm构建过程中使用的工作区具有相同的
工作区
,但是npm安装
无法在工作区
中找到package.json
ws(workSpace){
def commandString = "npm install ; npm rebuild node-sass ; ng build"
executeCommand(commandString, repositoryName)
}
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
'''
让我知道如果工作 您应该删除注释,并将其替换为管道,以便在另一个完成后一个接一个地运行任务
sh '''
npm install ||
npm rebuild node-sass ||
ng build --prod --configuration=cloud
'''
让我知道如果工作 将注释放在文字字符串中会将它们包含在文字字符串中。您可能应该从
脚本中删除这些注释:
@MattSchuchard Make sense在文本字符串中的注释将包括在文本字符串中。您可能应该从脚本中删除这些内容:
@MattSchuchard有意义